int main(int argc, char **argv) { /* Notice we do not init the PVR here, that is handled by Open GL */ glKosInit(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, 640.0f / 480.0f, 0.1f, 100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* Load a PVR texture to OpenGL */ GLuint texID = glTextureLoadPVR("/rd/wp001vq.pvr", 0, 0); buildDemoArray(); while(1) { /* Draw the "scene" */ RenderCallback(texID); /* Finish the frame - Notice there is no glKosBegin/FinshFrame */ glutSwapBuffers(); } return 0; }
int main(int argc, char **argv) { /* Notice we do not init the PVR here, that is handled by Open GL */ glKosInit(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, 640.0f / 480.0f, 0.1f, 100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* Load two PVR textures to OpenGL */ GLuint texID0 = glTextureLoadPVR("/rd/wp001vq.pvr", 0, 0); GLuint texID1 = glTextureLoadPVR("/rd/FlareWS_256.pvr", 0, 0); while(1) { /* Draw the "scene" */ RenderCallback(texID0, texID1); /* Finish the frame */ glutSwapBuffers(); } return 0; }
void Win32Window::MessageHook() { LARGE_INTEGER qwTicksPerSec = { 0, 0 }; LARGE_INTEGER qwTime; LONGLONG tickspersec; MSG msg; POINT p; double last, current; double delta, accum = 0; bool render = true; if( CreateCallback ) (*CreateCallback)(this); ShowWindow(hwnd, SW_SHOWDEFAULT); UpdateWindow(hwnd); ZeroMemory(&msg, sizeof(msg)); GetCursorPos(&p); ScreenToClient(hwnd, &p); QueryPerformanceFrequency(&qwTicksPerSec); tickspersec = qwTicksPerSec.QuadPart; QueryPerformanceCounter(&qwTime); last = (qwTime.QuadPart % tickspersec) / (double)tickspersec; while( msg.message != WM_QUIT ) { QueryPerformanceCounter(&qwTime); current = (qwTime.QuadPart % tickspersec) / (double)tickspersec; if (current < last) delta = ((1.0 + current) - last); else delta = (current - last); last = current; accum += delta; mousedx = mousedy = 0; while( accum > 0.1f ) { accum -= 0.1f; while( PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE) ) { TranslateMessage(&msg); DispatchMessage(&msg); if( msg.message == WM_CLOSE ) render = false; if( msg.message == WM_QUIT ) break; } if( msg.message == WM_QUIT ) break; if( render && UpdateCallback ) UpdateCallback(0.1f); } if( render && msg.message != WM_QUIT ) { if( RenderCallback && glcontextid != -1 ) RenderCallback(this, (float)accum / 0.1f, (float)delta); } } }
//-------------------------------------------------------------------------------------- // Name: RenderMesh() // Desc: Renders the mesh geometry //-------------------------------------------------------------------------------------- VOID Mesh::RenderMesh( MESH_DATA* pMesh, DWORD dwFlags ) { D3DVertexBuffer* pVB = &pMesh->m_VB; DWORD dwNumVertices = pMesh->m_dwNumVertices; D3DIndexBuffer* pIB = &pMesh->m_IB; DWORD dwVertexSize = pMesh->m_dwVertexSize; D3DPRIMITIVETYPE dwPrimType = pMesh->m_dwPrimType; DWORD dwNumSubsets = pMesh->m_dwNumSubsets; MESH_SUBSET* pSubsets = &pMesh->m_pSubsets[0]; if( dwNumVertices == 0 ) return; // Set the vertex stream g_pd3dDevice->SetStreamSource( 0, pVB, 0, dwVertexSize ); g_pd3dDevice->SetIndices( pIB ); // Set the vertex declaration if( 0 == ( dwFlags & MESH_NOVERTEXDECL ) ) { g_pd3dDevice->SetVertexDeclaration( pMesh->m_pVertexDecl ); } // Render the subsets for( DWORD i = 0; i < dwNumSubsets; i++ ) { BOOL bRender = FALSE; // Render the opaque subsets, unless the user asked us not to if( 0 == ( dwFlags & MESH_ALPHAONLY ) ) { if( 0 == ( dwFlags & MESH_NOMATERIALS ) ) { if( pSubsets[i].mtrl.Diffuse.a >= 1.0f ) bRender = TRUE; } else bRender = TRUE; } // Render the transparent subsets, unless the user asked us not to if( 0 == ( dwFlags & MESH_OPAQUEONLY ) ) { if( 0 == ( dwFlags & MESH_NOMATERIALS ) ) { if( pSubsets[i].mtrl.Diffuse.a < 1.0f ) bRender = TRUE; } } if( bRender ) { // Set the texture, unless the user asked us not to if( 0 == ( dwFlags & MESH_NOTEXTURES ) && pSubsets[i].pTexture ) g_pd3dDevice->SetTexture( 0, pSubsets[i].pTexture ); // Call the callback, so the app can tweak state before rendering // each subset BOOL bRenderSubset = RenderCallback( i, &pSubsets[i], dwFlags ); // Draw the mesh subset if( bRenderSubset ) { g_pd3dDevice->DrawIndexedPrimitive( dwPrimType, 0, 0, 0, pSubsets[i].dwIndexStart, pSubsets[i].dwPrimitiveCount ); } } } }