void CChessGUI::DrawScrean() { DrawBackground(); DrawGameBoard(); DrawPieces(); DrawTurn(); DrawMessage(); }
void Mesh::drawVBOs() { // scale it so it fits in the window Vec3f center; bbox.getCenter(center); float s = 1/bbox.maxDim(); glScalef(s,s,s); glTranslatef(-center.x(),-center.y(),-center.z()); // setup the light Vec3f light_position = LightPosition(); GLfloat position[4] = { float(light_position.x()),float(light_position.y()),float(light_position.z()),1 }; glLightfv(GL_LIGHT1, GL_POSITION, position); if (args->glsl_enabled) { glEnable(GL_DEPTH_TEST); glClearColor(0,0,0,1.0f); glEnable(GL_CULL_FACE); //glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); //BEGIN SHADOW FUN/////////////=================================== //First step: Render from the light POV to a FBO, story depth values only glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,fboId); //Rendering offscreen //Using the fixed pipeline to render to the depthbuffer glUseProgramObjectARB(0); // In the case we render the shadowmap to a higher resolution, the viewport must be modified accordingly. glViewport(0,0,args->width * SHADOW_MAP_RATIO,args->height* SHADOW_MAP_RATIO); // Clear previous frame values glClear(GL_DEPTH_BUFFER_BIT); //Disable color rendering, we only want to write to the Z-Buffer glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); //LIGHT POSITION========================================================================================== setupMatrices(float(light_position.x()),float(light_position.y()),float(light_position.z()), 10,10,1); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45,args->width/args->height,1.0f,1000.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt((float)light_position.x(),(float)light_position.y(),(float)light_position.z(),0,0,0,0,1,0); // Culling switching, rendering only backface, this is done to avoid self-shadowing glCullFace(GL_FRONT); //===========Draw the Things=================================================================================== InsertColor(floor_color); DrawFloor(); //startTranslate(0,0,0); //glutSolidCube(1); InsertColor(mesh_color); glUseProgramObjectARB(GLCanvas::program); glColor3b(GLbyte(240-127), GLbyte(184-127), GLbyte(0-127)); DrawMesh(table, board_tri_verts_VBO); DrawPieces(editBoard()); //endTranslate(); glUseProgramObjectARB(0); //============================================================================================================= //Save modelview/projection matrice into texture7, also add a biais setTextureMatrix(); // Now rendering from the camera POV, using the FBO to generate shadows glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0); glViewport(0,0,args->width,args->height); //Enabling color write (previously disabled for light POV z-buffer rendering) glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // Clear previous frame values glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Using the shadow shader glUseProgramObjectARB(GLCanvas::program); glUniform1iARB(shadowMapUniform,7); glActiveTextureARB(GL_TEXTURE7); glBindTexture(GL_TEXTURE_2D,depthTextureId); Vec3f cam_position = camera->camera_position; Vec3f interest = camera->point_of_interest; //CAMERA MATRIX======================================================================================================= //setupMatrices(cam_pos[0],cam_pos[1],cam_pos[2],interest[0],interest[1],interest[2]); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45,args->width/args->height,1.0f,1000.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt((float)cam_position.x(),(float)cam_position.y(),(float)cam_position.z(),(float)interest.x(),(float)interest.y(),(float)interest.z(),0,1,0); glCullFace(GL_BACK); //============================Draw the things InsertColor(floor_color); DrawFloor(); //startTranslate(0,0,0); //glutSolidCube(1); InsertColor(mesh_color); glUseProgramObjectARB(GLCanvas::program); glColor3b(GLbyte(240-127), GLbyte(184-127), GLbyte(0-127)); DrawMesh(table, board_tri_verts_VBO); DrawPieces(editBoard()); //endTranslate(); glUseProgramObjectARB(0); //============================All the things // DEBUG only. this piece of code draw the depth buffer onscreen //* glUseProgramObjectARB(0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-args->width/2,args->width/2,-args->height/2,args->height/2,1,20); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColor4f(1,1,1,1); glActiveTextureARB(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,depthTextureId); glEnable(GL_TEXTURE_2D); glTranslated(0,0,-1); glBegin(GL_QUADS); glTexCoord2d(0,0);glVertex3f(0,0,0); glTexCoord2d(1,0);glVertex3f(args->width/2,0,0); glTexCoord2d(1,1);glVertex3f(args->width/2,args->width/2,0); glTexCoord2d(0,1);glVertex3f(0,args->height/2,0); glEnd(); glDisable(GL_TEXTURE_2D); //*/ //glutSwapBuffers(); glDisable(GL_STENCIL_TEST); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glDepthMask(1); //END SHADOW FUN////////////////////////////////////////////////// } else { InsertColor(floor_color); DrawFloor(); InsertColor(mesh_color); glColor3b(GLbyte(240-127), GLbyte(184-127), GLbyte(0-127)); DrawMesh(table, board_tri_verts_VBO); if(args->board_control) { DrawControlMap(); } DrawPieces(editBoard()); } // ------------------------- // ADDITIONAL VISUALIZATIONS (for debugging) glColor3f(1,1,0); //DrawLight(); if (args->bounding_box) { glColor3f(0,0,0); bbox.drawVBOs(); } HandleGLError(); }