int CTreeOutCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CReportCtrl::OnCreate(lpCreateStruct) == -1) return -1; ModifyStyle(0, RVS_SHOWHGRID|RVS_SHOWVGRID|RVS_EXPANDSUBITEMS); //ModifyProperty(RVP_SEPARATOR, 0x01); // 初始化颜色表 InsertColor(0, RGB(255,255,225)); // 淡黄 InsertColor(1, RGB(0,0,0)); // 黑 InsertColor(2, RGB(255,255,255)); // 白 InsertColor(3, RGB(255,0,0)); // 红 InsertColor(4, RGB(0,255,0)); // 绿 InsertColor(5, RGB(0,0,255)); // 蓝 InsertColor(6, RGB(128,128,128)); // 灰 InsertColor(7, RGB(128,0,0)); // 半红 InsertColor(8, RGB(0,128,0)); // 半绿 InsertColor(9, RGB(0,0,128)); // 半蓝 return 0; }
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(); }
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); // -------------------------- // Render Mesh InsertColor(mesh_color); glEnable(GL_TEXTURE_2D); if (args->glsl_enabled) { glUseProgramObjectARB(GLCanvas::program); glActiveTexture(GL_TEXTURE0); // Height Map glActiveTexture(GL_TEXTURE0); GLint mapLoc = glGetUniformLocationARB(GLCanvas::program, "terrainMap"); glBindTexture(GL_TEXTURE_2D, texture[0]); glUniform1iARB(mapLoc, 0); // Normal Map glActiveTexture(GL_TEXTURE1); GLint normLoc = glGetUniformLocationARB(GLCanvas::program, "normalMap"); glBindTexture(GL_TEXTURE_2D, texture[1]); glUniform1iARB(normLoc, 1); // Stone Texture glActiveTexture(GL_TEXTURE2); GLint stoneLoc = glGetUniformLocationARB(GLCanvas::program, "texStone"); glBindTexture(GL_TEXTURE_2D, texture[2]); glUniform1iARB(stoneLoc, 2); // Grass Texture glActiveTexture(GL_TEXTURE3); GLint grassLoc = glGetUniformLocationARB(GLCanvas::program, "texGrass"); glBindTexture(GL_TEXTURE_2D, texture[3]); glUniform1iARB(grassLoc, 3); // Snow Texture glActiveTexture(GL_TEXTURE4); GLint snowLoc = glGetUniformLocationARB(GLCanvas::program, "texSnow"); glBindTexture(GL_TEXTURE_2D, texture[4]); glUniform1iARB(snowLoc, 4); glActiveTexture(GL_TEXTURE0); } else { glBindTexture(GL_TEXTURE_2D, texture[0]); } DrawMesh(); if (args->glsl_enabled) { glUseProgramObjectARB(0); } glDisable(GL_TEXTURE_2D); DrawPlateVisualization(); // ------------------------- // Render Light (for debugging) glColor3f(1,1,0); DrawLight(); HandleGLError(); }