Lightweight gui system ---------------------- rale - 2006 Modify GUIinclude.h if you are not using SDL. // INIT GUIHolder *holder; holder = new GUIHolder(); holder->init(); holder->addWidget(new GUIButton(125,635,14,14,"PREVIEW", "Preview")); holder->addWidget(new GUIButton(125,665,14,14,"DOEFFECT", "Do effect")); holder->addWidget(new GUIToggleButton(125,695,14,14,"UNDOLAST", "Undo last"),false); // RENDER holder->render(0); // float = deltatime (not needed currently..) holder->processEvent(GUIMouseMovedEvent(event.motion.x,event.motion.y)); holder->processEvent(GUIKeyboardEvent(SDL_GetKeyName(event.key.keysym.sym), false, false)); holder->processEvent(GUIKeyboardEvent(SDL_GetKeyName(event.key.keysym.sym), true, false)); std::string returnvalue = holder->processEvent(GUIMousePressedEvent(event.motion.x,event.motion.y, false, true, false)); if(returnvalue == "PREVIEW") doPreview; //etc // DEINIT this->holder->deinit(); if(this->holder!=0) delete holder; holder = 0;Shadow mapping with Traction engine ----------------------------------- // TODO: Add info about blurring the depth buffer Steps to get shadows into your scene: 1. Render scene from lights point of view 2. Render scene from camera point of view ----------------------------------- Steps explained: 1. Render scene from lights point of view // -- Render glExt.bindDepthFBO(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Add offsets to remove z-fight glPolygonOffset(2.0f, 2.0f); glEnable(GL_POLYGON_OFFSET_FILL); gluLookAt( LOOK FROM LIGHT POSITION ); // Store needed matrices for step 2 Matrix4 light_mat_proj; glGetFloatv(GL_PROJECTION_MATRIX, light_mat_proj); Matrix4 light_mat_modelview; glGetFloatv(GL_MODELVIEW_MATRIX, light_mat_modelview); // Draw your scene here drawObjects(); // -- End rendering to buffer glDisable(GL_POLYGON_OFFSET_FILL); glExt.unbindFBO(); 2. Render scene from camera point of view gluLookAt( LOOK FROM CAMERA POSITION ); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glTranslatef(0.5, 0.5, 0.5); // [0.0, 1.0], not [-1.0, 1.0] glScalef(0.5, 0.5, 0.5); glMultMatrixf(light_mat_proj); // multiply texture matrix glMultMatrixf(light_mat_modelview); // finally, multiply by the *inverse* of the *current* modelview matrix Matrix4 s_mat_m; glGetFloatv(GL_MODELVIEW_MATRIX, s_mat_m); // Invert matrix s_mat_m = s_mat_m.makeInverseTranspose(); s_mat_m = s_mat_m.makeTranspose(); glMultMatrixf(s_mat_m); glMatrixMode(GL_MODELVIEW); // Bind your shadowmapping shader shaders.shadowMap->bind(); // Bind shadow texture & pass it to shader glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, glExt.shadowMap); shaders.jytky->setUniform1i("shadowMap", 0); // Draw your scene here with lighting and stuff drawObjects(); shaders.unbind(); // Restore normal texture matrix and stuff glMatrixMode(GL_TEXTURE); glLoadIdentity(); glEnable(GL_TEXTURE_2D); glMatrixMode(GL_MODELVIEW); ----------------------------------- If post procession is wanted on the shadowed scene apply it after the texture matrix is restored. Otherwise things will get messy :-) ----------------------------------- Check the facts and maths from: http://en.wikipedia.org/wiki/Shadow_mapping ----------------------------------- - rale 12.3.2007