// Display 3D game void display3D(void) { // Set up OpenGL for 3D rendering setup3D(); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, g_store.image_store.grass); glBegin(GL_QUADS); glColor3f(1.0f, 1.0f, 1.0f); for (int i = 0; i < g_store.maze_store.height*2+1; i++) { for (int j = 0; j < g_store.maze_store.width*2+1; j++) { glTexCoord2f(0.0f, 0.0f); glVertex3f((float)i, 0.0f, (float)j); glTexCoord2f(1.0f, 0.0f); glVertex3f((float)i+1, 0.0f, (float)j); glTexCoord2f(1.0f, 1.0f); glVertex3f((float)i+1, 0.0f, (float)j+1); glTexCoord2f(0.0f, 1.0f); glVertex3f((float)i, 0.0f, (float)j+1); } } glEnd(); glBindTexture(GL_TEXTURE_2D, g_store.image_store.crate); glBegin(GL_QUADS); glColor3f(1.0f, 1.0f, 1.0f); for (int i = 0; i < g_store.maze_store.numBoxes; i++) { CollisionObject box = g_store.maze_store.boxes[i]; drawTexturedBox(box.position, box.dimensions); } glEnd(); glDisable(GL_TEXTURE_2D); }
/** * @brief Main run function for this stage. Performs all processing. * */ void BoxesStage::run(void) { //Save state for next draw call glPushMatrix(); //Save state to change back to 2D after switching to 3D glPushMatrix(); //Switch to 3D setup3D(); //Disable blending temporarily so we can draw the teapot. Draw the teapot, and enable it again. glDisable(GL_BLEND); drawTeapot(); glEnable(GL_BLEND); //Switch back for 2D glPopMatrix(); //Draw GUI on top drawGUI(); //And revert for the next draw call glPopMatrix(); }
int main(void) { static FPSCounterState fps; uint32 frameFence = 0; uint32 nextFence; Intr_Init(); Intr_SetFaultHandlers(SVGA_DefaultFaultHandler); SVGA_Init(); GMR_Init(); Heap_Reset(); SVGA_SetMode(0, 0, 32); SVGA3D_Init(); Screen_Init(); ScreenDraw_Init(0); initScreens(); setup3D(); /* * One big circle, and a smaller one that overlaps the top-right * corner. (This tests positive and negative clipping extremes.) */ prepareCircle(&circles[0], 650, 400, 300); prepareCircle(&circles[1], 1000, 50, 250); while (1) { if (SVGA3DUtil_UpdateFPSCounter(&fps)) { Console_MoveTo(900, 730); Console_Format("%s ", fps.text); } drawCube(); /* * Flow control- one frame in the FIFO at a time. */ nextFence = SVGA_InsertFence(); SVGA_SyncToFence(frameFence); frameFence = nextFence; present(); } return 0; }