/**----------------------------------------------------------------------------- * 화면 그리기 *------------------------------------------------------------------------------ */ VOID Render() { /// 후면버퍼와 Z버퍼 초기화 g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(200,200,200), 1.0f, 0 ); /// 애니메이션 행렬설정 Animate(); /// 렌더링 시작 if( SUCCEEDED( g_pd3dDevice->BeginScene() ) ) { g_pd3dDevice->SetTexture( 0, g_pTexDiffuse ); /// 0번 텍스쳐 스테이지에 텍스쳐 고정(색깔맵) g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ); /// 0번 텍스처 스테이지의 확대 필터 g_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 ); /// 0번 텍스처 : 0번 텍스처 인덱스 사용 g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE); g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); DrawMesh( &g_matAni ); if ( !g_bHideFrustum ) { g_pFrustum->Draw( g_pd3dDevice ); } /// 렌더링 종료 g_pd3dDevice->EndScene(); } /// 후면버퍼를 보이는 화면으로! g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); }
/*!**************************************************************************** @Function DrawBalloons @Input psProgram Program to use mProjection Projection matrix to use mView View matrix to use pmModels A pointer to an array of model matrices iNum Number of balloons to draw @Description Draws balloons. ******************************************************************************/ void OGLES2Glass::DrawBalloons(Program* psProgram, PVRTMat4 mProjection, PVRTMat4 mView, PVRTMat4* pmModels, int iNum) { // Use shader program glUseProgram(psProgram->uiId); // Bind texture glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_uiBalloonTex); PVRTMat4 mModelView, mMVP; for (int i = 0; i < iNum; ++i) { mModelView = mView * pmModels[i]; mMVP = mProjection * mModelView; glUniformMatrix4fv(psProgram->auiLoc[eMVMatrix], 1, GL_FALSE, mModelView.ptr()); glUniformMatrix4fv(psProgram->auiLoc[eMVPMatrix], 1, GL_FALSE, mMVP.ptr()); // Calculate and set the model space light direction PVRTVec3 vLightDir = pmModels[i].inverse() * PVRTVec4(19, 22, -50, 0); vLightDir = vLightDir.normalize(); glUniform3fv(psProgram->auiLoc[eLightDir], 1, vLightDir.ptr()); // Calculate and set the model space eye position PVRTVec3 vEyePos = mModelView.inverse() * PVRTVec4(0.0f, 0.0f, 0.0f, 1.0f); glUniform3fv(psProgram->auiLoc[eEyePos], 1, vEyePos.ptr()); // Now that the uniforms are set, call another function to actually draw the mesh. DrawMesh(0, &m_Balloon, &m_puiBalloonVbo, &m_puiBalloonIndexVbo, 3); } }
void CMeshViewer::Draw3D(float TimeDelta) { guard(CMeshViewer::Draw3D); assert(Inst); if (GShowDebugInfo) { // draw axis BindDefaultMaterial(true); glBegin(GL_LINES); for (int i = 0; i < 3; i++) { CVec3 tmp = nullVec3; tmp[i] = 1; glColor3fv(tmp.v); tmp[i] = 70; glVertex3fv(tmp.v); glVertex3fv(nullVec3.v); } glEnd(); glColor3f(1, 1, 1); } // draw mesh glPolygonMode(GL_FRONT_AND_BACK, Wireframe ? GL_LINE : GL_FILL); //?? bWireframe is inside Inst, but used here only ? DrawMesh(Inst); unguard; }
int main() { Window window; Camera camera(window.GetAspectRatio(), glm::vec3(2.0, 2.0, 1.0)); Mesh* sphereMesh = CreateMesh("sphere.obj", "sphere"); Shader defaultShader("Shaders/defaultShader.vert", "Shaders/defaultShader.frag", "defaultShader"); SetupMesh(sphereMesh, defaultShader); do { window.Clear(); DrawMesh(*sphereMesh, camera, defaultShader); camera.front = sphereMesh->position; sphereMesh->rotY -= 0.016; { if (glfwGetKey(window.GetWindowInstance(), GLFW_KEY_W) == GLFW_PRESS) { sphereMesh->position.x -= 0.16; } else if (glfwGetKey(window.GetWindowInstance(), GLFW_KEY_S) == GLFW_PRESS) { sphereMesh->position.x += 0.16; } if (glfwGetKey(window.GetWindowInstance(), GLFW_KEY_A) == GLFW_PRESS) { sphereMesh->position.z += 0.16; } else if (glfwGetKey(window.GetWindowInstance(), GLFW_KEY_D) == GLFW_PRESS) { sphereMesh->position.z -= 0.16; } } window.Update(); } while (!window.Closed() && glfwGetKey(window.GetWindowInstance(), GLFW_KEY_ESCAPE) != GLFW_PRESS); delete sphereMesh; }
void DrawShape(NxShape* shape, const NxVec3& color) { switch(shape->getType()) { case NX_SHAPE_PLANE: DrawPlane(shape); break; case NX_SHAPE_BOX: DrawBox(shape, color); break; case NX_SHAPE_SPHERE: DrawSphere(shape, color); break; case NX_SHAPE_CAPSULE: DrawCapsule(shape, color); break; case NX_SHAPE_CONVEX: DrawConvex(shape, color); break; case NX_SHAPE_MESH: DrawMesh(shape, color); break; case NX_SHAPE_WHEEL: DrawWheelShape(shape); break; default: break; } }
/*!**************************************************************************** @Function DrawBall @Description Draws the reflective and refractive ball onto the screen. ******************************************************************************/ void OGLES2Glass::DrawBall() { // Set model view projection matrix PVRTMat4 mModel, mModelView, mMVP; mModel = PVRTMat4::Scale(6.0f, 6.0f, 6.0f); mModelView = m_mView * mModel; mMVP = m_mProjection * mModelView; // Use shader program glUseProgram(m_aEffectPrograms[m_iEffect].uiId); // Bind textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_uiParaboloidTexture); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_CUBE_MAP, m_uiCubeTex); glUniformMatrix4fv(m_aEffectPrograms[m_iEffect].auiLoc[eMVPMatrix], 1, GL_FALSE, mMVP.ptr()); // Set model matrix PVRTMat3 Model3x3 = PVRTMat3(mModel); glUniformMatrix3fv(m_aEffectPrograms[m_iEffect].auiLoc[eMMatrix], 1, GL_FALSE, Model3x3.ptr()); // Set eye position in model space PVRTVec4 vEyePosModel; vEyePosModel = mModelView.inverse() * PVRTVec4(0, 0, 0, 1); glUniform3fv(m_aEffectPrograms[m_iEffect].auiLoc[eEyePos], 1, &vEyePosModel.x); // Now that the uniforms are set, call another function to actually draw the mesh DrawMesh(0, &m_Ball, &m_puiVbo, &m_puiIndexVbo, 2); }
static void Display( void ) { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glPushMatrix(); glRotatef(Xrot, 1, 0, 0); glRotatef(Yrot, 0, 1, 0); glRotatef(Zrot, 0, 0, 1); /* Position the gravity source */ { GLfloat x, y, z, r = 0.5; x = r * cos(Phi); y = r * sin(Phi); z = 1.0; glProgramLocalParameter4fARB(GL_VERTEX_PROGRAM_ARB, 30, x, y, z, 1); glDisable(GL_VERTEX_PROGRAM_ARB); glBegin(GL_POINTS); glColor3f(1,1,1); glVertex3f(x, y, z); glEnd(); } glEnable(GL_VERTEX_PROGRAM_ARB); DrawMesh(8, 8); glPopMatrix(); glutSwapBuffers(); }
void MakeLamp(void) { static GLfloat ambient_torus[3] = { 0.2125, 0.1275, 0.054}; // Torus static GLfloat diffuse_torus[3] = {0.714, 0.4284, 0.18144}; static GLfloat specular_torus[3]= { 0.393548, 0.271906, 0.166721}; if(lamp_id != -1) { glDeleteLists(lamp_id,1); } lamp_id = glGenLists(1); glNewList(lamp_id, GL_COMPILE); glDisable(GL_TEXTURE_2D); glDepthMask (GL_FALSE); glMaterialfv(GL_FRONT,GL_AMBIENT, ambient_torus); glMaterialfv(GL_FRONT,GL_DIFFUSE, diffuse_torus); glMaterialfv(GL_FRONT,GL_SPECULAR, specular_torus); glMaterialf (GL_FRONT, GL_SHININESS, 76.8); #ifdef USE_BINDBUFFER DrawMesh(vbo4, vinx4, FACES4_COUNT); #else DrawMesh(FACES4_COUNT, (char *)&vertexs4, (char *)&indexes4); #endif glDisable(GL_CULL_FACE); glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glRotatef(90.0,1.0,0.0,0.0); glTranslatef(-1.0,0.7,0.7); static const GLshort Vertices1[] = {0,0,0,0,12,0,2,0,0,2,12,0}; static const GLshort ColorData1[] = {1,1,1,1,1,1,1,1,1,1,1,1}; glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glPushMatrix(); glVertexPointer(3, GL_SHORT, 0, Vertices1); glColorPointer(3, GL_SHORT, 0, ColorData1); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glPopMatrix(); glPushMatrix(); glTranslatef(0.0,0.0,-1.4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glPopMatrix(); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glPolygonMode(GL_FRONT,GL_FILL); glDepthMask (GL_TRUE); glEnable(GL_CULL_FACE); glEnable(GL_TEXTURE_2D); glEndList(); }
/*!**************************************************************************** @Function RenderScene @Return bool true if no error occured @Description Main rendering loop function of the program. The shell will call this function every frame. eglSwapBuffers() will be performed by PVRShell automatically. PVRShell will also manage important OS events. Will also manage relevent OS events. The user has access to these events through an abstraction layer provided by PVRShell. ******************************************************************************/ bool OGLES2Fog::RenderScene() { // Clear the color and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Keyboard input (cursor to change fog function) if (PVRShellIsKeyPressed(PVRShellKeyNameLEFT)) { m_eFogMode = EFogMode((m_eFogMode + eNumFogModes - 1) % eNumFogModes); } if (PVRShellIsKeyPressed(PVRShellKeyNameRIGHT)) { m_eFogMode = EFogMode((m_eFogMode + 1) % eNumFogModes); } // Use the loaded shader program glUseProgram(m_ShaderProgram.uiId); // Bind texture glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_uiTexture); // Set uniforms glUniform1i(m_ShaderProgram.uiFogFuncLoc, m_eFogMode); // Rotate and translate the model matrix PVRTMat4 mModel = PVRTMat4::RotationY(m_fAngleY); m_fAngleY += PVRT_PI / 90; mModel.preTranslate(0, 0, 500 * cos(m_fPositionZ) - 450); m_fPositionZ += (2*PVRT_PI)*0.0008f; // Feed Projection and Model View matrices to the shaders PVRTMat4 mModelView = m_mView * mModel; PVRTMat4 mMVP = m_mProjection * mModelView; glUniformMatrix4fv(m_ShaderProgram.uiModelViewLoc, 1, GL_FALSE, mModelView.ptr()); glUniformMatrix4fv(m_ShaderProgram.uiMVPMatrixLoc, 1, GL_FALSE, mMVP.ptr()); // Pass the light direction transformed with the inverse of the ModelView matrix // This saves the transformation of the normals per vertex. A simple dot3 between this direction // and the un-transformed normal will allow proper smooth shading. PVRTVec3 vMsLightDir = (PVRTMat3(mModel).inverse() * PVRTVec3(1, 1, 1)).normalized(); glUniform3fv(m_ShaderProgram.uiLightDirLoc, 1, vMsLightDir.ptr()); /* Now that the model-view matrix is set and the materials ready, call another function to actually draw the mesh. */ DrawMesh(0); // Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools m_Print3D.DisplayDefaultTitle("Fog", "", ePVRTPrint3DLogoIMG); m_Print3D.Print3D(0.3f, 7.5f, 0.75f, PVRTRGBA(255,255,255,255), "Fog Mode: %s", g_FogFunctionList[m_eFogMode]); m_Print3D.Flush(); return true; }
void CollisionMesh::DrawMesh(const Matrix& projection, const Matrix& view) { D3DXVECTOR3 color = m_colour; if(m_partition) { color = m_engine->diagnostic()->GetColor(m_partition->GetColor()); } DrawMesh(projection, view, color); }
//this function takes the index position of a cover, the linear interpolation too the next position and the index of the //texture it is displaying. The matrices and texture load are applied and then draw mesh is called to draw an individual cover. void OGLES2Coverflow::DrawInPosition(int index, float queueLerp, int coverIndex) { PVRTVec3 pos, posNext; float angle = 0.f; float backgroundPosition = -8.f; float backgroundAngle = (PVRT_PI/2.5); float distInQueue = 3.f; queueLerp += (float)index; coverIndex += index; if(coverIndex >= g_i32CoverNo) { coverIndex = coverIndex - g_i32CoverNo; } if(coverIndex < 0) { coverIndex = g_i32CoverNo; } pos = 0.f; pos.x = (queueLerp - eFront) * distInQueue; if(queueLerp > eFront - 1 && queueLerp < eFront + 1) { float lerpAbs = (float) fabs(queueLerp - eFront); pos.z = backgroundPosition * lerpAbs; angle = backgroundAngle * (queueLerp - eFront); pos.x += 2.0f * (queueLerp - eFront); } else { queueLerp - eFront < 0 ? angle = -backgroundAngle : angle = backgroundAngle; pos.z = backgroundPosition; if(queueLerp - eFront > 0) pos.x += 2.0; else pos.x -= 2.0; } PVRTMat4 mTrans, mRotation; PVRTMatrixTranslation(mTrans, pos.x, pos.y, pos.z); PVRTMatrixRotationY(mRotation, angle); PVRTMat4 mModelView, mMVP; mModelView = m_mView * mTrans * mRotation; mMVP = m_mProjection * mModelView; glUniformMatrix4fv(m_ShaderProgram.uiMVPMatrixLoc, 1, GL_FALSE, mMVP.f); glBindTexture(GL_TEXTURE_2D, g_Covers[coverIndex].ui32TexID); DrawMesh(); }
// --------------------------------------------------------------- void MyPVRDemo::RenderStatue(const PVRTMat4& mxModel, const PVRTMat4& mxCam, const PVRTVec3& vLightPos, const StatueShader* pShader) { PVRTMat4 mxModelView = mxCam * mxModel; PVRTMat4 mxMVP = m_mxProjection * mxModelView; PVRTVec3 vLightPosModel = vLightPos; // Light position in World space glUniform3fv(pShader->uiLightPos, 1, vLightPosModel.ptr()); glUniformMatrix4fv(pShader->uiMVP, 1, GL_FALSE, mxMVP.ptr()); glUniformMatrix4fv(pShader->uiModelView, 1, GL_FALSE, mxModelView.ptr()); DrawMesh(enumMODEL_Statue, FLAG_VRT | FLAG_TEX0 | FLAG_NRM | FLAG_TAN); }
//this funciton takes the index position of a cover, the linear interpolation too the next position and the index of the //texture it is displaying. The matrices and texture load are applied and then draw mesh is called to draw an individual cover. void OGLESCoverflow::DrawInPosition(int index, float queueLerp, int coverIndex) { PVRTVec3 pos, posNext; float angle = 0.0f; float backgroundPosition = -8.0f; float backgroundAngle = (PVRT_PIf/2.5f); float distInQueue = 3.0f; queueLerp += (float)index; coverIndex += index; if(coverIndex >= g_i32CoverNo) { coverIndex = coverIndex - g_i32CoverNo; } if(coverIndex < 0) { coverIndex = g_i32CoverNo; } pos = 0.0f; pos.x = (queueLerp - eFront) * distInQueue; if(queueLerp > eFront - 1 && queueLerp < eFront + 1) { float lerpAbs = (float) fabs(queueLerp - eFront); pos.z = backgroundPosition * lerpAbs; angle = backgroundAngle * (queueLerp - eFront); pos.x += 2.0f * (queueLerp - eFront); } else { queueLerp - eFront < 0 ? angle = -backgroundAngle : angle = backgroundAngle; pos.z = backgroundPosition; if(queueLerp - eFront > 0) pos.x += 2.0f; else pos.x -= 2.0f; } PVRTMat4 mTrans, mRotation; PVRTMatrixTranslation(mTrans, pos.x, pos.y, pos.z); PVRTMatrixRotationY(mRotation, angle); glLoadMatrixf((mTrans * m_mView * mRotation).f); glClientActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, g_Covers[coverIndex].ui32TexID); DrawMesh(); }
void DDModel::RenderItSelf() { if ( m_IncludeAnimation ) { DrawAnimationMesh(); } else { DrawMesh(); } }
/*!**************************************************************************** @Function DrawEnvironment @Description Draws the environment, land, bridge etc. ******************************************************************************/ void OGLESFur::DrawEnvironment() { PVRTMat4 mWorld; // Draw land SetMaterial(&c_pMaterial[3], m_aTexIDs[eTexGrass]); DrawMesh(eLand); // Draw bridge // Use the material from before but use a different texture SetMaterial(0, m_aTexIDs[eTexBridge]); DrawMesh(eBridge); // Draw Ground if(m_i32WaterPlaneNo) { glVertexPointer(3, GL_FLOAT, sizeof(SVertex), &m_pvPlaneWater->x); glNormalPointer(GL_FLOAT, sizeof(SVertex), &m_pvPlaneWater->nx); glTexCoordPointer(2, GL_FLOAT, sizeof(SVertex), &m_pvPlaneWater->tu); SetMaterial(0, m_aTexIDs[eTexWater]); // Draw primitive glDrawArrays(GL_TRIANGLE_FAN, 0, m_i32WaterPlaneNo); } // Draw Cloud if(m_i32CloudPlaneNo) { glVertexPointer(3, GL_FLOAT, sizeof(SVertex), &m_pvPlaneCloud->x); glNormalPointer(GL_FLOAT, sizeof(SVertex), &m_pvPlaneCloud->nx); glTexCoordPointer(2, GL_FLOAT, sizeof(SVertex), &m_pvPlaneCloud->tu); SetMaterial(0, m_aTexIDs[eTexCloud]); // Draw primitive glEnable(GL_BLEND); glDrawArrays(GL_TRIANGLE_FAN, 0, m_i32CloudPlaneNo); glDisable(GL_BLEND); } }
void CRenderer::ProcessNode(CNode* node) { std::vector<CNode*> *vec = node->GetNodeVector(); //Обновляем нод, рендерим сущности //Log("Node is updated\n"); glTranslatef(node->GetPosX(), node->GetPosY(), node->GetPosZ()); for(int i = 0; i < node->GetObjVector()->size(); i++) { if(node->GetObjVector()->at(i)->GetType()==OBJECT_ENTITY) { //TO DO: //Берем шейдер, соотвутствующий сущности и активируем его //----- CMaterial* mat; CShader* sh; if((mat = ((CEntity*)node->GetObjVector()->at(i))->GetMaterial())!=0) { if((sh = mat->GetShader())!=0) { if(sh->IsCompiled()) { glUseProgram(sh->GetProgramId()); } } } DrawMesh(((CEntity*)node->GetObjVector()->at(i))->GetMesh()); glUseProgram(0); } } glDisable(GL_DEPTH_TEST); glBegin(GL_LINES); glColor3f(0.5, 1, 0.5); glVertex3f(0, 0, 0); glVertex3f(0, 1, 0); glColor3f(1, 0.5, 0.5); glVertex3f(0, 0, 0); glVertex3f(1, 0, 0); glColor3f(0.5, 0.5, 1); glVertex3f(0, 0, 0); glVertex3f(0, 0, 1); glColor3f(1,1,1); glEnd(); glEnable(GL_DEPTH_TEST); for(int i = 0; i < vec->size(); i++) { ProcessNode(vec->at(i)); } glTranslatef(-node->GetPosX(), -node->GetPosY(), -node->GetPosZ()); }
void CMeter2DGraphView::paintGL() { TRACE_FUN( Frequently, "CMeter2DGraphView::paintGL" ); CAbstractMeterView::paintGL(); if( model()->hasValues() ) { DrawTitles(); DrawMesh(); DrawValueGraph(); } }
//++++++++++++++++++++++++++++++++++++++++++++++++ //描画 //--in-------------------------------------------- // //--out------------------------------------------- // //++++++++++++++++++++++++++++++++++++++++++++++++ void LINE_PARTICLE::Draw() { int a; glDepthMask(GL_FALSE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glDisable(GL_LIGHTING); glEnable(GL_ALPHA_TEST); glDisable(GL_CULL_FACE); //glEnable(GL_ALPHA_TEST); glActiveTexture(GL_TEXTURE0); VECTOR3 vWork = m_Obj->m_Pos - m_Pos; if(GetAsyncKeyState(VK_F1) & 0x8000) { a = 11111; } if(m_Live) { for(int i = 0; i < LINE_NUM; i++) { glPushMatrix(); glTranslatef(m_Pos.x, m_Pos.y, m_Pos.z); //glRotatef(((GLfloat)m_Rad[i] * 180 / M_PI), (GLfloat)vWork.x, (GLfloat)vWork.y , (GLfloat)vWork.z); //Y軸回転 //glRotatef(90.0f, (GLfloat)1.0, (GLfloat)0.0f , (GLfloat)0.0f); //X軸回転 glRotatef(((GLfloat)m_RadY[i] * 180 / M_PI), (GLfloat)0.0, (GLfloat)1.0f , (GLfloat)0); //Y軸回転 glRotatef(((GLfloat)m_RadX[i] * 180 / M_PI), (GLfloat)1.0f, (GLfloat)0.0f , (GLfloat)0.0f); //X軸回転 //glRotatef(m_ObjRad, (GLfloat)0.0, (GLfloat)1.0f , (GLfloat)0); //Y軸回転 //α値セット glColor3f(1.0f, 1.0f, 1.0f); glScalef(0.3f, 0.3f, 0.3f); //glScalef(0.5f, 0.5f, 0.5f); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_TexID); DrawMesh(m_Line[i], m_TexOffset[i]); glPopMatrix(); } } glDisable(GL_ALPHA_TEST); glDisable(GL_BLEND); //ブレンド無効 glDisable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); glDepthMask(GL_TRUE); }
/*!**************************************************************************** @Function DrawDuck @Description Draws duck. ******************************************************************************/ void OGLESFur::DrawDuck() { glPushMatrix(); // Apply the transformation for the duck glMultMatrixf(m_mDuckWorld.f); // Draw the duck body SetMaterial(&c_pMaterial[3], m_aTexIDs[eTexSkin]); DrawMesh(eDuckBody); // Draw the duck's eyes SetMaterial(&c_pMaterial[1], 0); DrawMesh(eDuckEyeL); DrawMesh(eDuckEyeR); // Draw his beak SetMaterial(&c_pMaterial[2], 0); DrawMesh(eDuckBeak); // Draw the fur shells DrawFurShells(); glPopMatrix(); }
static void DrawModel( const DrawModelCommand &cmd ) { for ( const auto *mesh : cmd.model->meshes ) { SDL_assert( mesh ); // this should never happen, surely SDL_assert( mesh->material && "DrawMesh with invalid material" ); mesh->material->Bind(); mesh->material->shaderProgram->SetUniform3( "u_Position", cmd.info.worldPos[0], cmd.info.worldPos[1], cmd.info.worldPos[2] ); DrawMesh( mesh ); } }
/*!**************************************************************************** @Function RenderScene @Return bool true if no error occurred @Description Main rendering loop function of the program. The shell will call this function every frame. eglSwapBuffers() will be performed by PVRShell automatically. PVRShell will also manage important OS events. Will also manage relevant OS events. The user has access to these events through an abstraction layer provided by PVRShell. ******************************************************************************/ bool OGLES2ParallaxBumpMap::RenderScene() { // Clear the color and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Use shader program glUseProgram(m_ShaderProgram.uiId); // Bind textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_uiBaseTex); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, m_uiNormalMap); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, m_uiHeightMap); // Calculate the model matrix PVRTMat4 mModel = PVRTMat4::Scale(g_CubeScale); mModel *= PVRTMat4::Translation(g_CubeTranslation); mModel *= PVRTMat4::RotationY(m_fAngleY); m_fAngleY += PVRT_PI / 450; // Set the Model View matrix PVRTMat4 mMV = m_mView * mModel; glUniformMatrix4fv(m_ShaderProgram.auiLoc[eModelViewMatrix], 1, GL_FALSE, mMV.ptr()); // Set the ModelViewIT Matrix PVRTMat4 mMIT = mMV.transpose(); mMIT = mMIT.inverseEx(); PVRTMat3 mMIT3x3 = PVRTMat3(mMIT); glUniformMatrix3fv(m_ShaderProgram.auiLoc[eNormal], 1, GL_FALSE, mMIT3x3.ptr()); // Set model view projection matrix PVRTMat4 mMVP = m_mViewProj * mModel; glUniformMatrix4fv(m_ShaderProgram.auiLoc[eModelViewProj], 1, GL_FALSE, mMVP.ptr()); // Set light position in eye space PVRTVec4 vEyeSpaceLightPos = m_mView * g_LightPos; glUniform3fv(m_ShaderProgram.auiLoc[eLightEyeSpacePos], 1, vEyeSpaceLightPos.ptr()); DrawMesh(0); // Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools m_Print3D.DisplayDefaultTitle("Parallax Bumpmap", "", ePVRTPrint3DSDKLogo); m_Print3D.Flush(); return true; }
/*!**************************************************************************** @Function RenderScene @Return bool true if no error occured @Description Main rendering loop function of the program. The shell will call this function every frame. eglSwapBuffers() will be performed by PVRShell automatically. PVRShell will also manage important OS events. Will also manage relevent OS events. The user has access to these events through an abstraction layer provided by PVRShell. ******************************************************************************/ bool OGLES3ComplexLighting::RenderScene() { // Clears the color and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Keyboard input (cursor to change light) if (PVRShellIsKeyPressed(PVRShellKeyNameLEFT)) { m_eLightType = ELightType((m_eLightType + eNumLightTypes - 1) % eNumLightTypes); } if (PVRShellIsKeyPressed(PVRShellKeyNameRIGHT)) { m_eLightType = ELightType((m_eLightType + 1) % eNumLightTypes); } // Use shader program glUseProgram(m_ShaderProgram.uiId); // Bind texture glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_uiTexture); glUniform1i(m_ShaderProgram.uiLightSelLoc, m_eLightType); // Rotate and Translation the model matrix PVRTMat4 mModel = PVRTMat4::RotationY(m_fAngleY); m_fAngleY += PVRT_PI / 150; // Set model view projection matrix PVRTMat4 mModelView = m_mView * mModel; PVRTMat4 mMVP = m_mProjection * mModelView; glUniformMatrix4fv(m_ShaderProgram.uiMVPMatrixLoc, 1, GL_FALSE, mMVP.ptr()); // Set model view matrix glUniformMatrix4fv(m_ShaderProgram.uiModelViewLoc, 1, GL_FALSE, mModelView.ptr()); // Set model view inverse transpose matrix PVRTMat3 mModelViewIT = PVRTMat3(mModelView).inverse().transpose(); glUniformMatrix3fv(m_ShaderProgram.uiModelViewITLoc, 1, GL_FALSE, mModelViewIT.ptr()); DrawMesh(0); // Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools m_Print3D.DisplayDefaultTitle("ComplexLighting", c_aszLightTypeList[m_eLightType], ePVRTPrint3DSDKLogo); m_Print3D.Flush(); return true; }
//Render the game GAME_DLL GAME_RENDER(Game_Render) { clock_t startRender = clock(); CalculateLookAtViewMatrix(&Cam, vec3(0, 0, -1), vec3(0, 1, 0)); CalculateModelMatrix(&transform); //Activate the shader shader.Activate(); glUniformMatrix4fv(glGetUniformLocation(shader.GetProgram(), "modelMatrix"), 1, false, CalculateMVP(&transform, &Cam).GetElemets()); GLenum error = glGetError(); //Draw the mesh DrawMesh(&test); error = glGetError(); clock_t endReender = clock(); computetime(startRender, endReender); }
void DoFrame() { static DWORD StartTime = timeGetTime(); DWORD Time = timeGetTime(); // Create and set the view transformation float Angle = (float)timeGetTime() / 1000.0f; D3DXMATRIX matView; D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3(1100.0f, 600.0f, -1200.0f), &D3DXVECTOR3(0.0f, 400.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); g_pD3DDevice->SetTransform(D3DTS_VIEW, &matView); // Clear the device and start drawing the scene g_pD3DDevice->Clear(NULL, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_RGBA(0,0,64,255), 1.0, 0); if(SUCCEEDED(g_pD3DDevice->BeginScene())) { // Draw the backdrop g_pD3DDevice->SetFVF(BACKDROPFVF); g_pD3DDevice->SetStreamSource(0, g_BackdropVB, 0, sizeof(sBackdropVertex)); g_pD3DDevice->SetTexture(0, g_BackdropTexture); g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); // Set world transformation (rotate based on time) D3DXMATRIX matWorld; D3DXMatrixRotationY(&matWorld, (float)timeGetTime() / 1000.0f); g_pD3DDevice->SetTransform(D3DTS_WORLD, &matWorld); // Draw base DrawMesh(g_BaseMesh); // Get the pointers to the meshes to use for morphing D3DXMESHCONTAINER_EX *pSourceMesh, *pTargetMesh; float Scalar; g_MorphAnim.Update("Dance", (Time-StartTime), TRUE, &pSourceMesh, &pTargetMesh, &Scalar); // Draw the morphing mesh using the time as a scalar (and rotate it) DrawMorphMesh(pSourceMesh, pTargetMesh, Scalar); // End the scene g_pD3DDevice->EndScene(); } // Present the scene to the user g_pD3DDevice->Present(NULL, NULL, NULL, NULL); }
/*!**************************************************************************** @Function DrawScene @Input bLight If true then the scene is drawn lit, otherwise it isn't @Description Draws the scene ******************************************************************************/ void OGLES3ShadowVolumes::DrawScene() { SPODNode* pNode; PVRTMat4 mWorld; PVRTMat4 mModelView, mMVP; // Use the shader program for the scene glUseProgram(m_BaseShader.uiId); // Go through the meshes drawing each one for(unsigned int i = 0; i < m_Scene.nNumMeshNode; ++i) { pNode = &m_Scene.pNode[i]; // Get the world matrix for this particular node. switch(i) { case eBigCog: mWorld = PVRTMat4::RotationZ(m_fBigCogAngle); break; case eSmallCog: mWorld = PVRTMat4::RotationZ(m_fSmallCogAngle); break; default: mWorld = m_Scene.GetWorldMatrix(*pNode); } // Pass the model-view-projection matrix (MVP) to the shader to transform the vertices mMVP = m_mProjection * m_mView * mWorld; glUniformMatrix4fv(m_BaseShader.auiLoc[eMVPMatrix], 1, GL_FALSE, mMVP.ptr()); // Pass the light position in model space to the shader PVRTVec4 vLightPosModel; vLightPosModel = mWorld.inverse() * m_vLightPosWorld; glUniform3fv(m_BaseShader.auiLoc[eLightPosModel], 1, &vLightPosModel.x); // Loads the correct texture using our texture lookup table glBindTexture(GL_TEXTURE_2D, m_puiTextures[pNode->nIdxMaterial]); // Draw the mesh node DrawMesh(i); } }
void Renderer::RenderFrame() { ClearScreen(); for( RenderRequest& req : mRenderRequests ) { glm::mat4 MVP = ( req.camera->GetProjectionMatrix() * req.camera->GetViewMatrix() ) * req.transform->GetModelToWorldMatrix(); req.material->GetShader()->SetUniform( "transform", MVP ); SetGPUState( *req.material->GetGPUState() ); switch( req.type ) { case XOF_RENDER_REQUEST_TYPE::RENDER_MESH: DrawMesh( *req.mesh, *req.material ); break; case XOF_RENDER_REQUEST_TYPE::RENDER_SPRITE: DrawSprite( *req.sprite, *req.material ); break; } } mRenderRequests.clear(); }
/*!**************************************************************************** @Function DrawScene @Input viewMat The view matrix to use for rendering @Description Draws the scene ******************************************************************************/ void OGLES2ShadowMapping::DrawScene(PVRTMat4 viewMat) { for (unsigned int i = 0; i < m_Scene.nNumMeshNode; ++i) { if(i == 1) continue; SPODNode& Node = m_Scene.pNode[i]; PVRTMat4 mWorld, mModelView; m_Scene.GetWorldMatrix(mWorld, Node); PVRTMatrixMultiply(mModelView, mWorld, viewMat); glUniformMatrix4fv(m_SimpleShaderProgram.uiModelViewMatrixLoc, 1, GL_FALSE, mModelView.f); DrawMesh(i); } }
/*!**************************************************************************** @Function RenderScene @Return bool true if no error occured @Description Main rendering loop function of the program. The shell will call this function every frame. eglSwapBuffers() will be performed by PVRShell automatically. PVRShell will also manage important OS events. Will also manage relevent OS events. The user has access to these events through an abstraction layer provided by PVRShell. ******************************************************************************/ bool OGLES2FastTnL::RenderScene() { // Clear the color and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Use shader program glUseProgram(m_ShaderProgram.uiId); // Bind texture glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_uiTexture); /* Now that the uniforms are set, call another function to actually draw the mesh. */ DrawMesh(0); // Rotate the model matrix PVRTMat4 mModel = PVRTMat4::RotationY(m_fAngleY); m_fAngleY += 0.02f; // Calculate model view projection matrix PVRTMat4 mMVP = m_mViewProj * mModel; // Feeds Projection Model View matrix to the shaders glUniformMatrix4fv(m_ShaderProgram.uiMVPMatrixLoc, 1, GL_FALSE, mMVP.ptr()); /* The inverse of a rotation matrix is the transposed matrix Because of v * M = transpose(M) * v, this means: v * R == inverse(R) * v So we don't have to actually invert or transpose the matrix to transform back from world space to model space */ PVRTVec3 vMsLightDir = (PVRTVec3(1, 1, 1) * PVRTMat3(mModel)).normalized(); glUniform3fv(m_ShaderProgram.uiLightDirLoc, 1, vMsLightDir.ptr()); // Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools m_Print3D.DisplayDefaultTitle("FastTnL", "", ePVRTPrint3DLogoIMG); m_Print3D.Flush(); return true; }
/*!**************************************************************************** @Function RenderScene @Return bool true if no error occured @Description Main rendering loop function of the program. The shell will call this function every frame. eglSwapBuffers() will be performed by PVRShell automatically. PVRShell will also manage important OS events. Will also manage relevent OS events. The user has access to these events through an abstraction layer provided by PVRShell. ******************************************************************************/ bool OGLES3PerturbedUvs::RenderScene() { // Clear the color and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Use shader program glUseProgram(m_ShaderProgram.uiId); // Bind textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_uiReflectTex); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, m_uiNormalTex); // Rotate and translate the model matrix PVRTMat4 mModel; mModel = PVRTMat4::RotationY(m_fAngleY); m_fAngleY += PVRT_PI / 210; // Set model view projection matrix PVRTMat4 mModelView, mMVP; mModelView = m_mView * mModel; mMVP = m_mProjection * mModelView; glUniformMatrix4fv(m_ShaderProgram.auiLoc[eMVPMatrix], 1, GL_FALSE, mMVP.ptr()); // Set eye position in model space PVRTVec4 vEyePosModel; vEyePosModel = mModelView.inverse() * PVRTVec4(0, 0, 0, 1); glUniform3fv(m_ShaderProgram.auiLoc[eEyePosModel], 1, &vEyePosModel.x); /* Now that the uniforms are set, call another function to actually draw the mesh. */ DrawMesh(0); // Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools m_Print3D.DisplayDefaultTitle("PerturbedUvs", "", ePVRTPrint3DSDKLogo); m_Print3D.Flush(); return true; }
void RigidBody::VDraw() { //Simple draw, just a cube. GLfloat mat[16]; m_Transform.FillColumnMajorArray(mat); //TODO : Transform all points in mesh rather than just doing a mult matrix glPushMatrix(); glMultMatrixf(mat); DrawMesh(); glPopMatrix(); /* if(m_DebugDraw) { m_AABB->DebugDraw(); } */ }