void RenderWorld() { glEnable(GL_LIGHTING); txrGround.BindTexture(); mtrGround.Apply(); glBegin(GL_QUADS); glNormal3f(0.0,1.0,0.0); glTexCoord2f(0.0, 0.0); glVertex3f(-700.0, -20, 700.0); glTexCoord2f(0.0, 1.0); glVertex3f(700.0, -20, 700.0); glTexCoord2f(1.0, 1.0); glVertex3f(700.0, -20, -700.0); glTexCoord2f(1.0, 0.0); glVertex3f(-700.0, -20, -700.0); glEnd(); txrGround.UnBindTexture(); /* glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP); glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); GLUquadricObj *obj; obj = gluNewQuadric(); gluQuadricDrawStyle( obj, GLU_FILL ); gluQuadricOrientation( obj, GLU_OUTSIDE ); gluQuadricTexture( obj, GL_TRUE ); gluQuadricNormals( obj, GLU_SMOOTH ); gluSphere(obj,800,360,180); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); */ glPushMatrix(); glRotatef(90,1,0,0); glScalef(800,800,800); txrSky.BindTexture(); mtrSpace.Apply(); glCallList(SphereList); txrSky.UnBindTexture(); glPopMatrix(); DrawEarth(); DrawMoon(); }
//-------------------------------------------------------------- // Draw this actor //-------------------------------------------------------------- void Actor::Draw() const { // Bind data Material* pMaterial = pMesh->GetMaterial(); Texture* pTexture = pMaterial->GetTexture(); pTexture->BindTexture(); pMesh->BindVertexBuffers(); // Draw glDrawElements(GL_TRIANGLES, pMesh->GetNumVertices(), GL_UNSIGNED_INT, 0); // Unbind data pMesh->UnbindVertexBuffers(); pTexture->UnbindTexture(); }
void DrawMoon() { static float fAngle = 0.0; glPushMatrix(); glRotatef(fAngle,0,1,0); glTranslatef(0,200,300); glScalef(20,20,20); txrMoon.BindTexture(); mtrMoon.Apply(); glCallList(SphereList); txrMoon.UnBindTexture(); glPopMatrix(); fAngle += 0.8; }
void DrawEarth() { static float fAngle = 0; glPushMatrix(); glTranslatef(0,200,300); glRotatef(fAngle,0,-1,0); glScalef(70,70,70); txrEarth.BindTexture(); mtrEarth.Apply(); glCallList(SphereList); txrEarth.UnBindTexture(); glPopMatrix(); fAngle+=0.5; }
void RenderScene(LPVOID lpParam) { // typecast lpParam to Render pointer Render* glRender = (Render*)lpParam; ////Rendering happens here//// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); int iModelViewLoc = glGetUniformLocation(spShader.GetShaderProgramID(), "modelViewMatrix"); int iProjectionLoc = glGetUniformLocation(spShader.GetShaderProgramID(), "projectionMatrix"); glUniformMatrix4fv(iProjectionLoc, 1, GL_FALSE, glm::value_ptr(*glRender->GetProjectionMatrix())); glm::mat4 mModelView = glm::lookAt(glm::vec3(0, 12, 27), glm::vec3(0, 0, 0), glm::vec3(0.0f, 1.0f, 0.0f)); glm::mat4 mCurrent; glBindVertexArray(uVAO); // texture binding set GL_ACTIVE_TEXTURE0, then tellfragment shader // that Sampler variable will get data from GL_ACTIVE_TEXTURE0 int iSimplerLoc = glGetUniformLocation(spShader.GetShaderProgramID(), "gSampler"); glUniform1i(iSimplerLoc, 0); tGold.BindTexture(0); // render cube mCurrent = glm::translate(mModelView, glm::vec3(-8.0f, 0.0f, 0.0f)); mCurrent = glm::scale(mCurrent, glm::vec3(10.0f, 10.0f, 10.0f)); mCurrent = glm::rotate(mCurrent, fRotationAngleCube, glm::vec3(1.0f, 0.0f, 0.0f)); glUniformMatrix4fv(iModelViewLoc, 1, GL_FALSE, glm::value_ptr(mCurrent)); glDrawArrays(GL_TRIANGLES, 0, 36); // Rendering of pyramid mCurrent = glm::translate(mModelView, glm::vec3(8.0f, 0.0f, 0.0f)); mCurrent = glm::scale(mCurrent, glm::vec3(10.0f, 10.0f, 10.0f)); mCurrent = glm::rotate(mCurrent, fRotationAnglePyramid, glm::vec3(0.0f, 1.0f, 0.0f)); glUniformMatrix4fv(iModelViewLoc, 1, GL_FALSE, glm::value_ptr(mCurrent)); glDrawArrays(GL_TRIANGLES, 36, 12); // render ground tSnow.BindTexture(); glUniformMatrix4fv(iModelViewLoc, 1, GL_FALSE, glm::value_ptr(mModelView)); glDrawArrays(GL_TRIANGLES, 48, 6); // user control if (Keys::Key(VK_UP))fCubeRotationSpeed -= appMain.sof(60.0f); if (Keys::Key(VK_DOWN))fCubeRotationSpeed += appMain.sof(60.0f); if (Keys::Key(VK_RIGHT))fPyramidRotationSpeed += appMain.sof(60.0f); if (Keys::Key(VK_LEFT))fPyramidRotationSpeed -= appMain.sof(60.0f); fRotationAngleCube += appMain.sof(fCubeRotationSpeed); fRotationAnglePyramid += appMain.sof(fPyramidRotationSpeed); // toggle FPS and V-Sync if (Keys::OneKey(VK_F1)) { bShowFPS = !bShowFPS; if (!bShowFPS) { SetWindowText(appMain.hWnd, "Test Open GL Window"); } } if (Keys::OneKey(VK_F2)) { bVSync = !bVSync; glRender->SetVerticalSynchronization(bVSync); } else if (Keys::OneKey(VK_F3)) { tGold.SetFiltering((tGold.GetMagnificationFilter() + 1) % 2, tGold.GetMinificationFilter()); tSnow.SetFiltering((tSnow.GetMagnificationFilter() + 1) % 2, tSnow.GetMinificationFilter()); displayTexFilerInfo(); } else if (Keys::OneKey(VK_F4)) { int newMinFilter = tSnow.GetMinificationFilter() == TEXTURE_FILTER_MIN_TRILINEAR ? TEXTURE_FILTER_MIN_NEAREST : tSnow.GetMinificationFilter() + 1; tSnow.SetFiltering(tSnow.GetMagnificationFilter(), newMinFilter); tGold.SetFiltering(tGold.GetMagnificationFilter(), newMinFilter); displayTexFilerInfo(); } if (bShowFPS) { char buff[55]; sprintf_s(buff, "FPS: %d, VSync: %s", glRender->GetFPS(), bVSync ? "On" : "Off"); SetWindowText(appMain.hWnd, buff); } if (Keys::OneKey(VK_ESCAPE)) PostQuitMessage(0); // call SwapBuffers glRender->SwapBuffersM(); }