void widgetCompositeImpl(widget *self) { float blendColour[4]; int i; // Do not composite unless we are visible if (!self->isVisible) { return; } // Save the current model-view matrix glPushMatrix(); // Translate such that (0,0) is the top-left of ourself glTranslatef(self->offset.x, self->offset.y, 0.0f); // Scale if necessary glScalef(self->scale.x, self->scale.y, 1.0f); // Rotate ourself glRotatef(self->rotate, 0.0f, 0.0f, 1.0f); // Set our alpha (blend colour) glGetFloatv(GL_BLEND_COLOR, blendColour); glBlendColor(1.0f, 1.0f, 1.0f, blendColour[3] * self->alpha); // Composite ourself glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self->textureId); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0.0f, self->size.y); glVertex2f(0.0f, self->size.y); glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); glTexCoord2f(self->size.x, self->size.y); glVertex2f(self->size.x, self->size.y); glTexCoord2f(self->size.x, 0.0f); glVertex2f(self->size.x, 0.0f); glEnd(); // Now our children for (i = 0; i < vectorSize(self->children); i++) { widget *child = vectorAt(self->children, i); // Composite widgetComposite(child); } // Restore the model-view matrix glPopMatrix(); // Restore the blend colour glBlendColor(1.0f, 1.0f, 1.0f, blendColour[3]); }
int main(int argc, char *argv[]) { SDL_Surface *screen; SDL_Event sdlEvent; bool quit = false; lua_State* L; // Make sure everything is cleaned up on quit atexit(SDL_Quit); // Init SDL if (SDL_Init(SDL_INIT_VIDEO) < -1) { fprintf(stderr, "SDL_init: %s\n", SDL_GetError()); exit(1); } // Enable UNICODE support (for key events) SDL_EnableUNICODE(true); // Enable double-buffering SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); // Enable sync-to-vblank SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); // 800x600 true colour screen = SDL_SetVideoMode(800, 600, 32, SDL_OPENGL); if (screen == NULL) { fprintf(stderr, "SDL_SetVideoMode: %s\n", SDL_GetError()); exit(1); } SDL_WM_SetCaption("Warzone UI Simulator", NULL); // Init OpenGL glClearColor(0.3f, 0.3f, 0.3f, 0.0f); glCullFace(GL_BACK); glEnable(GL_BLEND); glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendColor(1.0f, 1.0f, 1.0f, 1.0f); glEnable(GL_TEXTURE_RECTANGLE_ARB); glViewport(0, 0, 800, 600); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 800, 600, 0.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* * Create the GUI */ widgetSDLInit(); L = lua_open_betawidget(); createGUI(L); // Main event loop while (!quit) { int i; while (SDL_PollEvent(&sdlEvent)) { if (sdlEvent.type == SDL_QUIT) { quit = true; } else { widgetHandleSDLEvent(&sdlEvent); } } // Fire timer events widgetFireTimers(); glClear(GL_COLOR_BUFFER_BIT); for (i = 0; i < vectorSize(windowGetWindowVector()); i++) { window *wnd = vectorAt(windowGetWindowVector(), i); widgetDraw(WIDGET(wnd)); widgetComposite(WIDGET(wnd)); } SDL_GL_SwapBuffers(); } lua_close(L); widgetSDLQuit(); return EXIT_SUCCESS; }