int FrameBuffer::_render(lua_State *l) { FrameBuffer *self = getself(FrameBuffer); lua_pushvalue(l, 2); // make sure the function is on top lua_pushinteger(l, self->width); lua_pushinteger(l, self->height); glPushAttrib(GL_VIEWPORT_BIT); glViewport(0, 0, self->width, self->height); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, self->fbo); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // don't do this glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(0, self->width, self->height, 0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); lua_call(l, 2, 0); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopAttrib(); return 0; }
int FrameBuffer::_draw(lua_State *l) { FrameBuffer *self = getself(FrameBuffer); Point size = {self->width, self->height}; if (lua_gettop(l) == 5) { size = Point::pop(l); } Point origin = Point::pop(l); // self->tex.draw(p.x, p.y); // this is upside down glBindTexture(GL_TEXTURE_2D, self->tex.texid); glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); glTexCoord2f(0, 1); glVertex2d(origin.x, origin.y); glTexCoord2f(1, 1); glVertex2d(origin.x + size.x, origin.y); glTexCoord2f(1, 0); glVertex2d(origin.x + size.x, origin.y + size.y); glTexCoord2f(0, 0); glVertex2d(origin.x, origin.y + size.y); glEnd(); return 0; }
static void *ll_thread(void *arg) { lua_State *L = (lua_State *)arg; openlibs(L); /* open nativethread library */ lua_pushcfunction(L, luaopen_nativethread); lua_pcall(L, 0, 0, 0); /* call main chunk passed as a string argument */ if (lua_pcall(L, 0, 0, 0) != 0) fprintf(stderr, "thread error: %s", lua_tostring(L, -1)); pthread_cond_destroy(&getself(L)->cond); lua_close(L); return NULL; }
static void *ll_thread(void *arg) { lua_State *L = (lua_State *)arg; openlibs(L); luaL_requiref(L, "lproc", luaopen_lproc, 1); lua_pop(L, 1); if(lua_pcall(L, 0, 0, 0) != 0) { fprintf(stderr, "thread error: %s", lua_tostring(L, -1)); } pthread_cond_destroy(&getself(L)->cond); lua_close(L); return NULL; }
static void waitonlist (lutok::state& state, const char *channel, LuaSDL::LuaThread **list) { LuaSDL::LuaThread *p = getself(state); /* link itself at the end of the list */ if (*list == NULL) { /* empty list? */ *list = p; p->previous = p->next = p; } else { p->previous = (*list)->previous; p->next = *list; p->previous->next = p->next->previous = p; } p->channel = channel; do { /* waits on its condition variable */ SDL_CondWait(p->cond, kernel_access); } while (p->channel); }
static void waitonlist(lua_State *L, const char *channel, Proc **list) { Proc *p = getself(L); if (*list == NULL) { *list = p; p->previous = p->next = p; } else { p->previous = (*list)->previous; p->next = *list; p->previous->next = p->next->previous = p; } p->channel = channel; do { pthread_cond_wait(&p->cond, &kernel_access); } while (p->channel); }
static int ll_thread (void *arg) { lutok::state * state = static_cast<lutok::state *>(arg); LuaSDL::moduleDef module; int t_top = state->get_top(); state->openLibs(); t_top = state->get_top(); LuaSDL::init_thread(*state, module); t_top = state->get_top(); lutok::registerLib(*state, "SDL", module); state->pop(1); t_top = state->get_top(); try{ state->pcall(0,0,0); }catch(lutok::api_error & error){ t_top = state->get_top(); const char * str = state->typeName(1); fprintf(stderr, "thread error: %s", error.what()); } SDL_DestroyCond(getself(state)->cond); state->close(); return NULL; }
int FrameBuffer::_bind(lua_State *l) { FrameBuffer *self = getself(FrameBuffer); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, self->fbo); return 0; }
int FrameBuffer::_bindTex(lua_State *l) { FrameBuffer *self = getself(FrameBuffer); self->tex.bind(); return 0; }