mirror of
https://github.com/lxsang/meta-rpi-diya.git
synced 2025-07-17 06:19:52 +02:00
initial commit
This commit is contained in:
22
recipes-example/example/example_0.1.bb
Normal file
22
recipes-example/example/example_0.1.bb
Normal file
@ -0,0 +1,22 @@
|
||||
SUMMARY = "bitbake-layers recipe"
|
||||
DESCRIPTION = "Recipe created by bitbake-layers"
|
||||
LICENSE = "MIT"
|
||||
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
|
||||
|
||||
DEPENDS += "libsdl2"
|
||||
FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
|
||||
SRC_URI = "file://sdl_test.cpp file://sdlgl.c "
|
||||
TARGET_CC_ARCH += "${LDFLAGS}"
|
||||
|
||||
do_compile() {
|
||||
${CXX} ${WORKDIR}/sdl_test.cpp `pkg-config --cflags --libs sdl2` -o ${WORKDIR}/sdl_test
|
||||
${CC} ${WORKDIR}/sdlgl.c `pkg-config --cflags --libs sdl2` -lGL -o ${WORKDIR}/sdlgl
|
||||
}
|
||||
|
||||
do_install() {
|
||||
install -d ${D}/usr/bin
|
||||
install -m 0755 ${WORKDIR}/sdl_test ${D}/usr/bin
|
||||
install -m 0755 ${WORKDIR}/sdlgl ${D}/usr/bin
|
||||
install -m 0755 ${WORKDIR}/sdl_test /tmp
|
||||
install -m 0755 ${WORKDIR}/sdlgl /tmp
|
||||
}
|
111
recipes-example/example/files/sdl_test.cpp
Normal file
111
recipes-example/example/files/sdl_test.cpp
Normal file
@ -0,0 +1,111 @@
|
||||
#include <SDL2/SDL.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
SDL_Init( 0 );
|
||||
|
||||
std::cout << "Testing video drivers..." << '\n';
|
||||
std::vector< bool > drivers( SDL_GetNumVideoDrivers() );
|
||||
for( int i = 0; i < drivers.size(); ++i )
|
||||
{
|
||||
drivers[ i ] = ( 0 == SDL_VideoInit( SDL_GetVideoDriver( i ) ) );
|
||||
SDL_VideoQuit();
|
||||
}
|
||||
|
||||
std::cout << "SDL_VIDEODRIVER available:";
|
||||
for( int i = 0; i < drivers.size(); ++i )
|
||||
{
|
||||
std::cout << " " << SDL_GetVideoDriver( i );
|
||||
}
|
||||
std::cout << '\n';
|
||||
|
||||
std::cout << "SDL_VIDEODRIVER usable :";
|
||||
for( int i = 0; i < drivers.size(); ++i )
|
||||
{
|
||||
if( !drivers[ i ] ) continue;
|
||||
std::cout << " " << SDL_GetVideoDriver( i );
|
||||
}
|
||||
std::cout << '\n';
|
||||
|
||||
if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 )
|
||||
{
|
||||
std::cerr << "SDL_Init(): " << SDL_GetError() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
std::cout << "SDL_VIDEODRIVER selected : " << SDL_GetCurrentVideoDriver() << '\n';
|
||||
|
||||
SDL_Window* window = SDL_CreateWindow
|
||||
(
|
||||
"SDL2",
|
||||
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
0,0,
|
||||
SDL_WINDOW_SHOWN
|
||||
);
|
||||
if( nullptr == window )
|
||||
{
|
||||
std::cerr << "SDL_CreateWindow(): " << SDL_GetError() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
std::cout << "SDL_RENDER_DRIVER available:";
|
||||
for( int i = 0; i < SDL_GetNumRenderDrivers(); ++i )
|
||||
{
|
||||
SDL_RendererInfo info;
|
||||
SDL_GetRenderDriverInfo( i, &info );
|
||||
std::cout << " " << info.name;
|
||||
}
|
||||
std::cout << '\n';
|
||||
SDL_SetWindowFullscreen(window,SDL_WINDOW_FULLSCREEN);
|
||||
SDL_Renderer* renderer = SDL_CreateRenderer( window, -1, SDL_RENDERER_ACCELERATED );
|
||||
if( nullptr == renderer )
|
||||
{
|
||||
std::cerr << "SDL_CreateRenderer(): " << SDL_GetError() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
SDL_RendererInfo info;
|
||||
SDL_GetRendererInfo( renderer, &info );
|
||||
std::cout << "SDL_RENDER_DRIVER selected : " << info.name << '\n';
|
||||
SDL_DisplayMode DM;
|
||||
SDL_GetCurrentDisplayMode(0, &DM);
|
||||
printf("Display size %dx%d\n", DM.w, DM.h);
|
||||
bool running = true;
|
||||
while( running )
|
||||
{
|
||||
SDL_Event ev;
|
||||
while( SDL_PollEvent( &ev ) )
|
||||
{
|
||||
switch (ev.type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
/* code */
|
||||
running = false;
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if(ev.key.keysym.sym == SDLK_ESCAPE)
|
||||
{
|
||||
running = false;
|
||||
}
|
||||
break;
|
||||
case SDL_FINGERDOWN:
|
||||
case SDL_FINGERMOTION:
|
||||
std::cout << "Mouse finger down: x = " << ev.tfinger.x << ", y = " << ev.tfinger.y << std::endl;
|
||||
SDL_WarpMouseInWindow(window, (int)(ev.tfinger.x*DM.w), (int)(ev.tfinger.y*DM.h));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor( renderer, rand() % 256, rand() % 256, rand() % 256, SDL_ALPHA_OPAQUE );
|
||||
SDL_RenderClear( renderer );
|
||||
SDL_RenderPresent( renderer );
|
||||
}
|
||||
|
||||
SDL_DestroyRenderer( renderer );
|
||||
SDL_DestroyWindow( window );
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
166
recipes-example/example/files/sdlgl.c
Normal file
166
recipes-example/example/files/sdlgl.c
Normal file
@ -0,0 +1,166 @@
|
||||
// To compile with gcc: (tested on Ubuntu 14.04 64bit):
|
||||
// g++ sdl2_opengl.cpp -lSDL2 -lGL
|
||||
// To compile with msvc: (tested on Windows 7 64bit)
|
||||
// cl sdl2_opengl.cpp /I C:\sdl2path\include /link C:\path\SDL2.lib C:\path\SDL2main.lib /SUBSYSTEM:CONSOLE /NODEFAULTLIB:libcmtd.lib opengl32.lib
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_opengl.h>
|
||||
#include <GL/gl.h>
|
||||
|
||||
typedef int32_t i32;
|
||||
typedef uint32_t u32;
|
||||
typedef int32_t b32;
|
||||
|
||||
#define WinWidth 480
|
||||
#define WinHeight 640
|
||||
|
||||
int main(int ArgCount, char **Args)
|
||||
{
|
||||
|
||||
u32 WindowFlags = SDL_WINDOW_OPENGL;
|
||||
SDL_Window *Window = SDL_CreateWindow("OpenGL Test", 0, 0, 0, 0, WindowFlags);
|
||||
assert(Window);
|
||||
SDL_GLContext Context = SDL_GL_CreateContext(Window);
|
||||
|
||||
static GLfloat v0[] = {-1.0f, -1.0f, 1.0f};
|
||||
static GLfloat v1[] = {1.0f, -1.0f, 1.0f};
|
||||
static GLfloat v2[] = {1.0f, 1.0f, 1.0f};
|
||||
static GLfloat v3[] = {-1.0f, 1.0f, 1.0f};
|
||||
static GLfloat v4[] = {-1.0f, -1.0f, -1.0f};
|
||||
static GLfloat v5[] = {1.0f, -1.0f, -1.0f};
|
||||
static GLfloat v6[] = {1.0f, 1.0f, -1.0f};
|
||||
static GLfloat v7[] = {-1.0f, 1.0f, -1.0f};
|
||||
static GLubyte red[] = {255, 0, 0, 255};
|
||||
static GLubyte green[] = {0, 255, 0, 255};
|
||||
static GLubyte blue[] = {0, 0, 255, 255};
|
||||
static GLubyte white[] = {255, 255, 255, 255};
|
||||
static GLubyte yellow[] = {0, 255, 255, 255};
|
||||
static GLubyte black[] = {0, 0, 0, 255};
|
||||
static GLubyte orange[] = {255, 255, 0, 255};
|
||||
static GLubyte purple[] = {255, 0, 255, 0};
|
||||
SDL_SetWindowFullscreen(Window,SDL_WINDOW_FULLSCREEN);
|
||||
SDL_DisplayMode DM;
|
||||
SDL_GetCurrentDisplayMode(0, &DM);
|
||||
printf("Display size %dx%d\n", DM.w, DM.h);
|
||||
int Running = 1;
|
||||
while (Running)
|
||||
{
|
||||
SDL_Event Event;
|
||||
while (SDL_PollEvent(&Event))
|
||||
{
|
||||
if (Event.type == SDL_KEYDOWN)
|
||||
{
|
||||
switch (Event.key.keysym.sym)
|
||||
{
|
||||
case SDLK_ESCAPE:
|
||||
Running = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (Event.type == SDL_QUIT)
|
||||
{
|
||||
Running = 0;
|
||||
}
|
||||
}
|
||||
|
||||
glViewport(0, 0, DM.w, DM.h);
|
||||
glClearColor(1.f, 0.f, 1.f, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
/* Send our triangle data to the pipeline. */
|
||||
glBegin(GL_TRIANGLES);
|
||||
|
||||
glColor4ubv(red);
|
||||
glVertex3fv(v0);
|
||||
glColor4ubv(green);
|
||||
glVertex3fv(v1);
|
||||
glColor4ubv(blue);
|
||||
glVertex3fv(v2);
|
||||
|
||||
glColor4ubv(red);
|
||||
glVertex3fv(v0);
|
||||
glColor4ubv(blue);
|
||||
glVertex3fv(v2);
|
||||
glColor4ubv(white);
|
||||
glVertex3fv(v3);
|
||||
|
||||
glColor4ubv(green);
|
||||
glVertex3fv(v1);
|
||||
glColor4ubv(black);
|
||||
glVertex3fv(v5);
|
||||
glColor4ubv(orange);
|
||||
glVertex3fv(v6);
|
||||
|
||||
glColor4ubv(green);
|
||||
glVertex3fv(v1);
|
||||
glColor4ubv(orange);
|
||||
glVertex3fv(v6);
|
||||
glColor4ubv(blue);
|
||||
glVertex3fv(v2);
|
||||
|
||||
glColor4ubv(black);
|
||||
glVertex3fv(v5);
|
||||
glColor4ubv(yellow);
|
||||
glVertex3fv(v4);
|
||||
glColor4ubv(purple);
|
||||
glVertex3fv(v7);
|
||||
|
||||
glColor4ubv(black);
|
||||
glVertex3fv(v5);
|
||||
glColor4ubv(purple);
|
||||
glVertex3fv(v7);
|
||||
glColor4ubv(orange);
|
||||
glVertex3fv(v6);
|
||||
|
||||
glColor4ubv(yellow);
|
||||
glVertex3fv(v4);
|
||||
glColor4ubv(red);
|
||||
glVertex3fv(v0);
|
||||
glColor4ubv(white);
|
||||
glVertex3fv(v3);
|
||||
|
||||
glColor4ubv(yellow);
|
||||
glVertex3fv(v4);
|
||||
glColor4ubv(white);
|
||||
glVertex3fv(v3);
|
||||
glColor4ubv(purple);
|
||||
glVertex3fv(v7);
|
||||
|
||||
glColor4ubv(white);
|
||||
glVertex3fv(v3);
|
||||
glColor4ubv(blue);
|
||||
glVertex3fv(v2);
|
||||
glColor4ubv(orange);
|
||||
glVertex3fv(v6);
|
||||
|
||||
glColor4ubv(white);
|
||||
glVertex3fv(v3);
|
||||
glColor4ubv(orange);
|
||||
glVertex3fv(v6);
|
||||
glColor4ubv(purple);
|
||||
glVertex3fv(v7);
|
||||
|
||||
glColor4ubv(green);
|
||||
glVertex3fv(v1);
|
||||
glColor4ubv(red);
|
||||
glVertex3fv(v0);
|
||||
glColor4ubv(yellow);
|
||||
glVertex3fv(v4);
|
||||
|
||||
glColor4ubv(green);
|
||||
glVertex3fv(v1);
|
||||
glColor4ubv(yellow);
|
||||
glVertex3fv(v4);
|
||||
glColor4ubv(black);
|
||||
glVertex3fv(v5);
|
||||
|
||||
glEnd();
|
||||
|
||||
SDL_GL_SwapWindow(Window);
|
||||
}
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user