Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package.preload['extern.sdl'] = function()
- local ffi = require 'ffi'
- ffi.cdef [[
- enum {
- SDL_INIT_VIDEO = 0x00000020,
- SDL_OPENGL = 0x00000002,
- SDL_RESIZABLE = 0x00000010,
- SDL_TIMESLICE = 10
- };
- typedef enum {
- SDL_GL_RED_SIZE, SDL_GL_GREEN_SIZE, SDL_GL_BLUE_SIZE, SDL_GL_ALPHA_SIZE,
- SDL_GL_BUFFER_SIZE,
- SDL_GL_DOUBLEBUFFER,
- SDL_GL_DEPTH_SIZE,
- SDL_GL_STENCIL_SIZE,
- SDL_GL_ACCUM_RED_SIZE,
- SDL_GL_ACCUM_GREEN_SIZE,
- SDL_GL_ACCUM_BLUE_SIZE,
- SDL_GL_ACCUM_ALPHA_SIZE,
- SDL_GL_STEREO,
- SDL_GL_MULTISAMPLEBUFFERS,
- SDL_GL_MULTISAMPLESAMPLES,
- SDL_GL_ACCELERATED_VISUAL,
- SDL_GL_SWAP_CONTROL
- } SDL_GLattr;
- typedef enum {
- SDL_NOEVENT = 0,
- SDL_ACTIVEEVENT = 1,
- SDL_KEYDOWN = 2,
- SDL_KEYUP = 3,
- SDL_MOUSEMOTION = 4,
- SDL_MOUSEBUTTONDOWN = 5,
- SDL_MOUSEBUTTONUP = 6,
- SDL_QUIT = 12,
- SDL_SYSWMEVENT = 13,
- SDL_VIDEORESIZE = 16,
- SDL_VIDEOEXPOSE = 17
- } SDL_EventType;
- typedef enum {
- SDLK_ESCAPE = 27,
- SDLK__FORCESIZE = 323
- } SDLKey;
- typedef enum {
- KMOD__FORCESIZE = 0x8000
- } SDLMod;
- typedef union SDL_Event {
- uint8_t type;
- struct { uint8_t type, gain, state; } active;
- struct {
- uint8_t type, which, state;
- struct { uint8_t scancode; SDLKey sym; SDLMod mod; uint16_t unicode; } keysym;
- } key;
- struct {
- uint8_t type, which, state;
- uint16_t x, y; int16_t xrel, yrel;
- } motion;
- struct {
- uint8_t type, which, button, state;
- uint16_t x, y;
- } button;
- struct { uint8_t type; int w, h; } resize;
- struct { uint8_t type; } expose;
- struct { uint8_t type; } quit;
- struct { uint8_t type; int code; void* data1; void* data2; } user;
- struct { uint8_t type; void* msg; } syswm;
- } SDL_Event;
- int SDL_Init(uint32_t flags);
- void* SDL_SetVideoMode(int width, int height, int bpp, uint32_t flags);
- int SDL_GL_SetAttribute(SDL_GLattr, int value);
- void SDL_Delay(uint32_t ms);
- int SDL_PollEvent(SDL_Event*);
- void SDL_GL_SwapBuffers();
- ]]
- return ffi.load 'SDL'
- end
- package.preload['extern.shivavg'] = function()
- local ffi = require 'ffi'
- ffi.cdef [[
- typedef int VGint;
- typedef float VGfloat;
- typedef enum {
- VG_FALSE = 0,
- VG_TRUE = 1
- } VGboolean;
- VGboolean vgCreateContextSH(VGint width, VGint height);
- void vgResizeSurfaceSH(VGint width, VGint height);
- void vgDestroyContextSH();
- typedef enum VGParamType {
- VG_CLEAR_COLOR = 0x1121,
- VGPARAMTYPE__FORCESIZE = 0x116A
- } VGParamType;
- void vgSetfv(VGParamType, VGint count, const VGfloat* values);
- void vgClear(VGint x, VGint y, VGint width, VGint height);
- ]]
- return ffi.load 'libOpenVG'
- end
- local bit = require 'bit'
- local ffi = require 'ffi'
- local sdl = require 'extern.sdl'
- local vg = require 'extern.shivavg'
- local screenWidth = 640;
- local screenHeight = 480;
- local screen;
- local blue = ffi.new('VGfloat[4]', 0, 0, 1, 1);
- function main()
- local e = ffi.new 'SDL_Event'
- local finished = false
- sdl.SDL_Init(sdl.SDL_INIT_VIDEO);
- sdl.SDL_GL_SetAttribute(sdl.SDL_GL_DOUBLEBUFFER, 1);
- sdl.SDL_GL_SetAttribute(sdl.SDL_GL_STENCIL_SIZE, 1);
- screen = sdl.SDL_SetVideoMode(screenWidth, screenHeight, 0, bit.bor(sdl.SDL_OPENGL, sdl.SDL_RESIZABLE));
- vg.vgCreateContextSH(screenWidth, screenHeight);
- vg.vgSetfv(vg.VG_CLEAR_COLOR, 4, blue);
- while not finished do
- while (sdl.SDL_PollEvent(e) ~= 0) do
- if (e.type == sdl.SDL_QUIT) then
- finished = true;
- elseif (e.type == sdl.SDL_KEYDOWN) then
- if (e.key.keysym.sym == sdl.SDLK_ESCAPE) then
- finished = true;
- end
- elseif (e.type == sdl.SDL_VIDEORESIZE) then
- screenWidth = e.resize.w;
- screenHeight = e.resize.h;
- screen = sdl.SDL_SetVideoMode(screenWidth, screenHeight, 0, bit.bor(sdl.SDL_OPENGL, sdl.SDL_RESIZABLE));
- vg.vgResizeSurfaceSH(screenWidth, screenHeight);
- end
- end
- vg.vgClear(0, 0, screenWidth, screenHeight);
- sdl.SDL_GL_SwapBuffers();
- sdl.SDL_Delay(sdl.SDL_TIMESLICE);
- end
- vg.vgDestroyContextSH();
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement