/////////////////////////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); // Move light under floor to light the "reflected" world glLightfv(GL_LIGHT0, GL_POSITION, fLightPosMirror); glPushMatrix(); glFrontFace(GL_CW); // geometry is mirrored, swap orientation glScalef(1.0f, -1.0f, 1.0f); DrawWorld(); glFrontFace(GL_CCW); glPopMatrix(); // Draw the ground transparently over the reflection glDisable(GL_LIGHTING); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); DrawGround(); glDisable(GL_BLEND); glEnable(GL_LIGHTING); // Restore correct lighting and draw the world correctly glLightfv(GL_LIGHT0, GL_POSITION, fLightPos); DrawWorld(); glPopMatrix(); // Do the buffer Swap glutSwapBuffers(); }
void LoseLife(char *reason) { //Draw cracked screen - but draw all the rest of the world & hud first CloseGraphics(); OpenGraphics(); DrawWorld(&world, cameraPos, cameraAngle); DrawHUD(); DrawArrow(cameraAngle.y); DrawRadarDots(true); DrawRadarArm(sweepAngle * sweepStepCount++); DrawRadarDots(false); //finally! DrawCrackedScreen(); SetTextColor(RED); DrawText(25,40,reason); if (--lives<=0) { SetTextColor(GREEN); DrawText(30,55,"GAME OVER!"); } Show(); PlaySound(SOUND_EXPLOSION); //dead? if (lives<=0) { Sleep(2000); //Reset back to splash screen ResetTimer(); mode=0; Splash(); } else { // Hit but still going InitialiseWorld(); } }
void draw_screen( void ) { // Step you_angle += ( 10 * you_velocity * you_turn ) / fps; float you_x_new = you_x - ( (float)sin(you_angle*piover180) * you_velocity * you_dir ) / fps; float you_z_new = you_z + ( (float)cos(you_angle*piover180) * you_velocity * you_dir ) / fps; int joel = boundCheck(you_x_new, you_x_new, you_z_new, you_z_new); // TODO change this to avoid repetition if (joel == 1) { you_x = you_x_new; you_z = you_z_new; } glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen and The Depth Buffer /* We don't want to modify the projection matrix. */ glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); you_compensate(); // Some nice material/colour settings glColorMaterial ( GL_FRONT_AND_BACK, GL_EMISSION ) ; glEnable ( GL_COLOR_MATERIAL ) ; glLoadIdentity(); you_compensate(); glTranslatef( 0.0f, 3.0f, 0.0f ); draw_cube(); DrawWorld(); if (debug) { glLoadIdentity(); glTranslatef(0, 0, -1); glColor3f(1, 1, 1); glRasterPos2f(-0.7f, -0.5f); glPrint("X: %f Z: %f Angle: %f Velocity: %f", you_x, you_z, you_angle, you_velocity); glRasterPos2f(-0.7f, 0.5f); glPrint("FPS: %f", fps); } if (joel == 12) { glLoadIdentity(); glTranslatef(0, 0, -1); glColor3f(1, 1, 1); glRasterPos2f(-0.7f, 0.5f); glPrint("The Cake,"); glRasterPos2f(-0.7f, 0.4f); glPrint("Is a Lie!!"); // glRasterPos2f(-0.7f, 0.3f); // glPrint("Third Line"); } Frames++; GLint t = SDL_GetTicks(); if (t - T0 >= 100) { GLfloat seconds = (t - T0) / 1000.0; fps = Frames / seconds; T0 = t; Frames = 0; } SDL_GL_SwapBuffers( ); }
//Render the array of sprites. void Graphics::Update(float dt) { //Clear the backbuffer and fill it with the background color. //The first parameter is the number of rectangles you are going to clear--0 means clear the whole thing. //The second parameter is the array of rectangle to clear--just set it to NULL. //The third parameter says what to clear (in this case, the render target, but could be a zbuffer or stencil buffer). //The fourth parameter is the color to fill the target with. //The fifth and last parameters are the values to fill the zbuffer and stencil buffer with (if necessary). pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 0.0f, 0); //Begin the scene if (SUCCEEDED(pDevice->BeginScene())) { DrawWorld( dt ); DrawDebugInfo(); //End the scene pDevice->EndScene(); } //Present the backbuffer contents to the display. //The parameters are: source rect, dest rect, dest window (NULL meaning the default window), and dirty region. pDevice->Present(NULL, NULL, NULL, NULL); }
void Draw3d() { Setup3dWorld(); DrawWorld(); //pointer u.pointer = GetOGLPos(int(u.mp.x), int(u.mp.y)); mPointer.Draw(u.pointer, 0); }
void main(void) { int key; intro(); clrscr(); gotoxy(35, 1); puts("Shooter97!"); NextBFire = (random(289)+11); do { DrawWorld(); if (!Hits()) { delay(75); BFireCount++; if (((BFireCount % NextBFire) == 0) && (!BFire)) { BFire = 1; BFireXPos = bgpos; NextBFire = (random(289)+11); } if (kbhit()) { key = getch(); if (key == 0) { key = getch(); } if (key == 75) { ggdir = -1; } if (key == 77) { ggdir = 1; } if ((key == 72) && (!GFire)) { GFire = 1; GFireXPos = ggpos; } if ((key == 113) || (key == 81)) { /* then die */ dead = 1; } } /* end of if kb hit */ } /* end of nobody got hit */ } while (!dead); clrscr(); switch (Hits()) { case -1 : { puts(" "); puts("The BadGuy shot you! GAME OVER!"); break; } case 1 : { puts(" "); puts("You shot the BadGuy! YOU WIN!"); break; } } puts(" "); puts("Thank you for playing Shooter97!"); }
void MapOverview::OnPaint(wxPaintEvent& event) { wxPaintDC dc(this); wxMemoryDC mem; mem.SelectObject(*draw_area); mem.Clear(); DrawWorld(mem,GetWorldHandler()); dc.DrawBitmap(*draw_area,MapDrawX,MapDrawY,1); }
void Vessel::Update(NetworkWriter* nw) { if (myPlayer) { SDL_Event event; while (SDL_PollEvent(&event)) { /*if (event.type == SDL_EventType::) { }*/ if (event.key.keysym.sym == SDLK_w) { myPlayer->pos += glm::vec2(0.0f, 0.02f); } if (event.key.keysym.sym == SDLK_s) { myPlayer->pos += glm::vec2(0.0f, -0.02f); } if (event.key.keysym.sym == SDLK_a) { myPlayer->pos += glm::vec2(-0.02f, 0.0f); } if (event.key.keysym.sym == SDLK_d) { myPlayer->pos += glm::vec2(0.02f, 0.0f); } if (event.key.keysym.sym == SDLK_o) { camera.zoom -= 0.001f; } if (event.key.keysym.sym == SDLK_p) { camera.zoom += 0.001f; } } /*if (keyStates[SDL_SCANCODE_W]) myPlayer->pos += glm::vec2(0.0f, 0.01f); if (keyStates[SDL_SCANCODE_S]) myPlayer->pos += glm::vec2(0.0f, -0.01f); if (keyStates[SDL_SCANCODE_A]) myPlayer->pos += glm::vec2(-0.01f, 0.0f); if (keyStates[SDL_SCANCODE_D]) myPlayer->pos += glm::vec2(0.01f, 0.0f); if (keyStates[SDL_SCANCODE_KP_MEMADD]) camera.zoom -= 0.001f; if (keyStates[SDL_SCANCODE_KP_MEMSUBTRACT]) camera.zoom += 0.001f;*/ //myPlayer->pos = glm::vec2(glm::cos(elapsedTime * 0.25f), glm::sin(elapsedTime * 0.5f)) * 11.0f; //UpdateChunks(false, nw); } DrawWorld(); }
void GameBase::Loop(){ SetZoom(); Init(); InitWorldPhysics(); while(wnd->isOpen()){ wnd->clear(clearColor); DoEvents(); CheckCollitions(); UpdateWorldPhysics(); DrawWorld(); wnd->display(); } }
// // Idle processing: ovvero cosa fare quando non hai nient'altro // da fare // long AboutWindow::onIdle(FXObject* , FXSelector, void* ) { IdleHandle = NULL; int w = OGLCanvas->getWidth(); int h = OGLCanvas->getHeight(); if (!GLInitialized) { if(onOGLConfigure(NULL, 0, NULL)) GLInitialized = true; else return 0; } if (!OGLCanvas->makeCurrent()) return 0; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (delta > 3100.0f) { startTime = getTime(); ++nShow; if (nShow > 3) nShow = 0; if (nShow == 3 && hehe) nShow = 99; } delta = ((getTime() - startTime) / 4.0f); ViewPerspective(w, h); glEnable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); glColor3f(1.0f, 1.0f, 1.0f); RenderToTexture(w, h); DrawBlur(10, 0.03f, w, h); glColor3ub(255, 240, 32); glEnable(GL_TEXTURE_2D); DrawWorld(); glFlush(); OGLCanvas->swapBuffers(); OGLCanvas->makeNonCurrent(); IdleHandle = getApp()->addChore(this, ID_IDLE); return 1; }
void OGL3_Renderer::UpdateScreen() { glViewport( 0, 0, (GLsizei)Engine->p_Window->GetSize().x, (GLsizei)Engine->p_Window->GetSize().y ); Clear( true, true, vec4(0,0.74,0.52,1) ); //m_Camera.angles = vec3(2,0,0); CalculateProjectionMatrix( m_Camera.origin, m_Camera.angles, m_Camera.fov, m_Camera.zNear, m_Camera.zFar ); Engine->p_Renderer->SetBlending( BLEND_DISABLED, BLEND_DISABLED ); Engine->p_Renderer->SetCulling( CULL_FRONT ); p_MainShader->Bind(); DrawWorld(); p_MainShader->Unbind(); }
// Renderizza la scena e la copia su una texture inline void AboutWindow::RenderToTexture(int w, int h) { // Set Our Viewport (Match Texture Size) glViewport(0, 0, 128, 128); DrawWorld(); glBindTexture(GL_TEXTURE_2D, BlurTexture); // Copy Our ViewPort To The Blur Texture (From 0,0 To 128,128... No Border) glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 0, 0, 128, 128, 0); glClearColor(0.0f, 0.0f, 0.0f, 0.5); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, w, h); }
//Splash screen void Splash() { ResetTimer(); //we're going to use it for random seed //Setup a world with a tank and a pyramid in specific places CloseGraphics(); OpenGraphics(); Point3d centre; world=CreateNewWorld(); //A tank pointing straight at us centre=CreatePoint(0.0,0.0,45.0); obj=CreateTank(GREEN, centre, 4.5); RotateObjectYAxis(&obj, 2.0 * PI / 360.0 * 195); AddObjectToWorld(&world, obj); //A yellow pyramid behind the tank and to the right centre=CreatePoint(10.0, 0.0, 70.0); obj=CreatePyramid(YELLOW, centre, 5.0); RotateObjectYAxis(&obj, 3.0*PI/5.0); AddObjectToWorld(&world, obj); //A blue cube behind the tank and to the left centre=CreatePoint(-10.0, 0.0, 60.0); obj=CreateCube(BLUE, centre, 5.0); RotateObjectYAxis(&obj, 195.0*PI/180.0); AddObjectToWorld(&world,obj); //Draw world, add splash graphics, prompt to start cameraPos=CreatePoint(0.0,5.0,0.0); cameraAngle=CreatePoint(0.0,0.0,0.0); DrawWorld(&world, cameraPos, cameraAngle); SetTextColor(GREEN); DrawText(5,25, "by RorschachUK"); SetTextColor(CYAN); DrawText(5,100, "Help"); DrawText(110,100,"Start"); DrawImage(logoImage, 5,5,RGBColor(253,255,252,0)); DrawImage(signatureImage, 135,24,BLACK); Show(); Sleep(100); mode=0; }
void Glut2DView::Display() { // clear screen and initialize coordinate system glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // draw world in its own coordinate system glPushMatrix(); TransformWorld(); DrawWorld(); glPopMatrix(); // draw graphics with the screen coordinate system DrawScreen(); // display new frame glutSwapBuffers(); }
void dxModel::Draw(const dxVec3 &vieworigin_, const dxVec3 &viewforward_, const dxVec3 &viewright_, const dxVec3 &viewup_) { if (!loaded) { return; } framecount++; viewleaf = PointInLeaf(vieworigin_); MarkLeaves(); renderer.SetupFrame(vieworigin_, viewforward_, viewright_, viewup_); DrawSkyBox(); DrawWorld(); DrawEntitiesOnList(); }
/////////////////////////////////////////////////////////////////////////////// // Render a frame. The owning framework is responsible for buffer swaps, // flushes, etc. void RenderScene(void) { static CStopWatch animationTimer; float yRot = animationTimer.GetElapsedSeconds() * 60.0f; // MoveCamera(); modelViewMatrix.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewMatrix.MultMatrix(mCamera); GLfloat vFloorColor[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; if(bUseFBO) { glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboName); #ifndef OPENGL_ES glDrawBuffers(3, fboBuffs); #endif glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Need light position relative to the Camera M3DVector4f vLightTransformed; m3dTransformVector4(vLightTransformed, vLightPos, mCamera); UseProcessProgram(vLightTransformed, vFloorColor, 0); } else { glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); #ifndef OPENGL_ES glDrawBuffers(1, windowBuff); #endif glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeline.GetModelViewProjectionMatrix(), vFloorColor, 0); } glBindTexture(GL_TEXTURE_2D, textures[0]); // Marble floorBatch.Draw(); DrawWorld(yRot); modelViewMatrix.PopMatrix(); if(bUseFBO) { // Direct drawing to the window glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); #ifndef OPENGL_ES glDrawBuffers(1, windowBuff); #endif glViewport(0, 0, screenWidth, screenHeight); #ifndef OPENGL_ES // Source buffer reads from the framebuffer object glBindFramebuffer(GL_READ_FRAMEBUFFER, fboName); // Copy greyscale output to the left half of the screen glReadBuffer(GL_COLOR_ATTACHMENT1); glBlitFramebuffer(0, 0, screenWidth/2, screenHeight, 0, 0, screenWidth/2, screenHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST ); // Copy the luminance adjusted color to the right half of the screen glReadBuffer(GL_COLOR_ATTACHMENT2); glBlitFramebuffer(screenWidth/2, 0, screenWidth, screenHeight, screenWidth/2, 0, screenWidth, screenHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST ); // Scale the unaltered image to the upper right of the screen glReadBuffer(GL_COLOR_ATTACHMENT0); glBlitFramebuffer(0, 0, screenWidth, screenHeight, (int)(screenWidth *(0.8)), (int)(screenHeight*(0.8)), screenWidth, screenHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR ); glBindTexture(GL_TEXTURE_2D, 0); #endif } // Do the buffer Swap glutSwapBuffers(); // Do it again glutPostRedisplay(); }
int main(){ // Create main window sf::RenderWindow window(sf::VideoMode(800, 700), "Sculptor"); window.EnableVerticalSync(true); gluPerspective(40.0, window.GetWidth()/window.GetHeight(), .2, 100); bool cooldown = false; objects.push_back(new_obj); window.SetActive(); sf::RectangleShape bottom; sf::RectangleShape side; sf::RectangleShape top; InitControlPanels(bottom, side, top, window); //Initialize(window); //alternate init glClearColor(0.2f, 0.2f, 0.2f, 1.0f); AltInit(); old_x = sf::Mouse::GetPosition(window).x; old_y = sf::Mouse::GetPosition(window).y; //Vertices = &(objects[0].aux_vertices[0]); //Indices = &(objects[0].aux_indices[0]); sf::Clock clock; cam.Move(TemplateVec(0.0, 0.0, 10.0)); cam.MoveForward(1.0); glMatrixMode(GL_MODELVIEW); float click_cooldown = 0.5f; // start game loop while(window.IsOpen()){ //process events if(HandleEvents(window)){ if(control_mode == 0) for(int o = 0; o < objects.size(); o++) objects[0].reset_colors(); cooldown = true; //check for barcode here if(barcode != -1) HandleBarcode(); } if(exiting) break; Handle3DEvents(window, cooldown, clock); //display rendered frame on screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); // Move the camera glLoadIdentity(); cam.Render(); DrawWorld(); glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); window.PushGLStates(); GUIRender(window, bottom, side, top); window.PopGLStates(); //display rendered frame on screen window.Display(); if(cooldown) click_cooldown -= clock.GetElapsedTime().AsSeconds(); if(click_cooldown <= 0.0f){ cooldown = false; click_cooldown = 0.5f; } clock.Restart(); } cout << "Exiting\n"; //Cleanup(); return 0; }
/******************************************************************** * Function : SimLoop() * Purpose : Performs a single Simulation Loop iteration. Includes * drawing. ********************************************************************/ int SimLoop(void) { static int nFramesPerSecond = 0; static int nFramesSinceLastTick; static DWORD LastTicks = 0; DWORD Ticks; HDC hDC; HFONT hOldFont; char s[80]; int slen; DDSURFACEDESC ddsd; DDBLTFX BltFx; HRESULT ddreturn; /* Perform a single step in our world. */ if (StepWorld(bForwardKey, bBackKey, bLeftKey, bRightKey, nState, nGauge)) { if (lpPrimary->IsLost() == DDERR_SURFACELOST) lpPrimary->Restore(); /* Clear the backbuffer. */ #if CLEARBCKGRND BltFx.dwSize = sizeof(BltFx); BltFx.dwFillColor = 255; ddreturn = lpBackbuffer->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &BltFx); #else ddreturn = DD_OK; #endif if (ddreturn == DD_OK) { /* While this is running, prepare * the drawing. */ if (PrepDrawWorld()) { /* Lock the surface. */ memset(&ddsd, 0, sizeof(DDSURFACEDESC)); ddsd.dwSize = sizeof(ddsd); ddreturn = lpBackbuffer->Lock(NULL, &ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL); if (ddreturn == DD_OK) { DrawWorld((unsigned char *)ddsd.lpSurface, (int)ddsd.lPitch); int nX, nY; static unsigned char dummy; unsigned char ni; ni = 0; for (nY = 0; nY < 16; nY++) for (nX = 0; nX < 16; nX++) { /* Draw a small block at (nX * 3, nY * 3) */ ((unsigned char *)ddsd.lpSurface)[(nY * 3 * ddsd.lPitch) + (nX * 3)] = ni; ((unsigned char *)ddsd.lpSurface)[(nY * 3 * ddsd.lPitch) + (nX * 3 + 1)] = ni; ((unsigned char *)ddsd.lpSurface)[((nY * 3 + 1) * ddsd.lPitch) + (nX * 3)] = ni; ((unsigned char *)ddsd.lpSurface)[((nY * 3 + 1) * ddsd.lPitch) + (nX * 3 + 1)] = ni; ni++; } lpBackbuffer->Unlock(NULL); /* And now write Frames per second. */ /* Increment Frame counter. */ nFramesSinceLastTick++; /* Get system tick count. */ Ticks = GetTickCount(); /* Update fps value every second. */ if (Ticks > (LastTicks + 1000)) { nFramesPerSecond = nFramesSinceLastTick; nFramesSinceLastTick = 0; LastTicks = Ticks; } /* Get a DC to the buffer & write count. */ if (DD_OK == lpBackbuffer->GetDC(&hDC)) { SetBkMode(hDC, TRANSPARENT); hOldFont = SelectObject(hDC, AppFont); /* Build a string for display. */ slen = wsprintf(s, "FPS : %d", nFramesPerSecond); /* And draw the text. */ SetTextColor(hDC, RGB(0,0,0)); SIZE sz; GetTextExtentPoint32(hDC, s, slen, &sz); RECT rc; rc.top = 0; rc.left = 16 * 3; rc.right = 16 * 3 + sz.cx + 10; rc.bottom = sz.cy + 10; DrawFrameControl(hDC, &rc, DFC_BUTTON, DFCS_BUTTONPUSH); TextOut(hDC, 16*3 + 5, 5, s, slen); SelectObject(hDC, hOldFont); lpBackbuffer->ReleaseDC(hDC); } /* Perform required pageflipping to make the surface * we drawed visible. */ ddreturn = lpPrimary->Flip(NULL, DDFLIP_WAIT); if (ddreturn == DD_OK) { return 1; } } } } } return 0; }
//Main program loop - Run gets called until it returns false bool Run() { //Main loop - get keypresses and interpret them keystate=GetRemoteKeys(); if(keystate & KEY_HOME) { return false; } switch(mode) { case 0: { //Splash screen if (keystate & KEY_INPUT2) { //Button B //Start game InitialiseGame(); PlaySound(SOUND_BEEP); } if (keystate & KEY_INPUT1) { //Button A //show help ShowHelp(); PlaySound(SOUND_BEEP); } } break; case 2: { //Help - wait for 'OK' press if (keystate & KEY_INPUT2) { //Button B //Reset back to splash screen ResetTimer(); mode=0; Splash(); PlaySound(SOUND_BEEP); } } break; case 1: { //Game if (keystate & KEY_INPUT1) { //Button A //Reset back to splash screen ResetTimer(); mode=0; Splash(); } if (keystate & KEY_RUN) { //Go button //Fire! PlaySound(SOUND_SHOOT); refreshCount = 0; int hit; hit = LineHitsObject(cameraPos, cameraAngle); if (hit == tankObjectIndex) { //we hit the tank! score += 100; CloseGraphics(); OpenGraphics(); DrawWorld(&world, cameraPos, cameraAngle); DrawHUD(); DrawExplosion(); DrawArrow(cameraAngle.y); DrawRadarDots(true); DrawRadarArm(sweepAngle * sweepStepCount++); DrawRadarDots(false); SetTextColor(CYAN); DrawText(6,100,"Quit"); Show(); PlaySound(SOUND_EXPLOSION); PlaceTank(cameraPos, cameraAngle); } } //Have the movement sticks changed? This bit doesn't care about buttons if((keystate & (KEY_RIGHT_BACK+KEY_RIGHT_FORWARD+KEY_LEFT_BACK+KEY_LEFT_FORWARD)) != (oldKeystate & (KEY_RIGHT_BACK+KEY_RIGHT_FORWARD+KEY_LEFT_BACK+KEY_LEFT_FORWARD))) { MoveCamera(&cameraPos, &cameraAngle, baselinePos, arrowRefAngle, ReadTimer(), oldKeystate); arrowRefAngle=cameraAngle.y; baselinePos=cameraPos; ResetTimer(); oldKeystate = keystate; if (keystate==0) //we've just stopped moving refreshCount=0; } if (mode==1) { if (sweepStepCount == SWEEPSTEPS) sweepStepCount=0; if (--behaviourCount<0) ChooseBehaviour(); MoveTank(); MoveCamera(&cameraPos, &cameraAngle, baselinePos, arrowRefAngle, ReadTimer(), oldKeystate); //is it time to reset the tank model? Otherwise it gradually gets distorted if (--resetCount<0) { //Refresh the tank model which is prone to getting distorted //due to cumulative inaccuracies of sin/cos approximations Point3d angle=world.objects[tankObjectIndex].heading; Point3d tankPos=world.objects[tankObjectIndex].centre; world.objects[tankObjectIndex]=tank; MoveObject(&(world.objects[tankObjectIndex]), tankPos); RotateObjectYAxis(&(world.objects[tankObjectIndex]), angle.y); resetCount=50; } //Is it time to redraw the world? if (--refreshCount<0) { //Seems a bit brutal to have to close graphics but it's //the only way to clear the screen that'll let us draw //on it properly again - ClearScreen or ClearRectangle mess up CloseGraphics(); OpenGraphics(); DrawWorld(&world, cameraPos, cameraAngle); DrawHUD(); refreshCount=2; } DrawArrow(cameraAngle.y); DrawRadarDots(true); DrawRadarArm(sweepAngle * sweepStepCount++); DrawRadarDots(false); SetTextColor(CYAN); DrawText(6,100,"Quit"); Show(); //just in case we changed mode... if (mode==0) Splash(); } } } Sleep(50); return true; }
void NWApp::Draw() { DrawWorld(); }
void OGL2_Renderer::UpdateScreen() { glViewport( 0, 0, (GLsizei)Engine->p_Window->GetSize().x, (GLsizei)Engine->p_Window->GetSize().y ); Clear( true, true, vec4(0,0.74,0.52,1) ); //m_Camera.angles = vec3(2,0,0); CalculateProjectionMatrix( m_Camera.origin, m_Camera.angles, m_Camera.fov, m_Camera.zNear, m_Camera.zFar ); Engine->p_Renderer->SetBlending( BLEND_DISABLED, BLEND_DISABLED ); Engine->p_Renderer->SetCulling( CULL_FRONT ); p_MainShader->Bind(); p_MainShader->SendUniform1i( p_MainShader->FindUniform("ColorMap"), 0 ); p_MainShader->SendUniform4f( p_MainShader->FindUniform("Color"), vec4(1) ); p_MainShader->SendMatrix4( p_MainShader->GetCoreUniform(0), ProjectionMatrix ); p_MainShader->SendMatrix4( p_MainShader->GetCoreUniform(1), ViewMatrix ); glPushAttrib( GL_ALL_ATTRIB_BITS ); { glEnable( GL_POLYGON_OFFSET_FILL ); glPolygonOffset( -2.5f, -2.5f ); glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); glLineWidth( 4.0f ); p_MainShader->SendUniform4f( p_MainShader->FindUniform("Color"), vec4(0,0,0,0) ); // outline color DrawWorld(); // Set the polygon mode to be filled triangles glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); //glEnable( GL_LIGHTING ); // Set the colour to the background p_MainShader->SendUniform4f( p_MainShader->FindUniform("Color"), vec4(1,1,1,1) ); DrawWorld(); } glPopAttrib(); p_MainShader->Unbind(); p_Ortho->OrthoProjection(); if( Game->level.gameState != GS_PLAYING/* || Engine->UI->IsMenuOpen( "main" ) || Engine->UI->IsMenuOpen( "play" ) */) { BindImage(0); p_MenuBgShader->Bind(); p_MenuBgShader->SendUniform2f( p_MenuBgShader->FindUniform("resolution"), Engine->p_Window->GetSize() ); p_MenuBgShader->SendUniform1f( p_MenuBgShader->FindUniform("time"), Engine->p_Timer->GetTime() ); p_Ortho->DrawQuad( vec4(0,0,640,480), vec4(1,1,1,1) ); p_MenuBgShader->Unbind(); } Engine->UI->Draw(); glColor4f(1,1,1,1); }
/////////////////////////////////////////////////////////////////////////////// // Render a frame. The owning framework is responsible for buffer swaps, // flushes, etc. void RenderScene(void) { static CStopWatch animationTimer; float yRot = animationTimer.GetElapsedSeconds() * 60.0f; M3DVector3f vCameraPos; M3DVector3f vCameraForward; M3DVector3f vMirrorPos; M3DVector3f vMirrorForward; cameraFrame.GetOrigin(vCameraPos); cameraFrame.GetForwardVector(vCameraForward); // Set position of mirror frame (camera) vMirrorPos[0] = 0.0; vMirrorPos[1] = 0.1f; vMirrorPos[2] = -6.0f; // view pos is actually behind mirror mirrorFrame.SetOrigin(vMirrorPos); // Calculate direction of mirror frame (camera) // Because the position of the mirror is known relative to the origin // find the direction vector by adding the mirror offset to the vector // of the viewer-origin vMirrorForward[0] = vCameraPos[0]; vMirrorForward[1] = vCameraPos[1]; vMirrorForward[2] = (vCameraPos[2] + 5); m3dNormalizeVector3(vMirrorForward); mirrorFrame.SetForwardVector(vMirrorForward); // first render from the mirrors perspective glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboName); glDrawBuffers(1, fboBuffs); glViewport(0, 0, mirrorTexWidth, mirrorTexHeight); // Draw scene from the perspective of the mirror camera modelViewMatrix.PushMatrix(); M3DMatrix44f mMirrorView; mirrorFrame.GetCameraMatrix(mMirrorView); modelViewMatrix.MultMatrix(mMirrorView); // Flip the mirror camera horizontally for the reflection modelViewMatrix.Scale(-1.0f, 1.0f, 1.0f); glBindTexture(GL_TEXTURE_2D, textures[0]); // Marble glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeline.GetModelViewProjectionMatrix(), vWhite, 0); floorBatch.Draw(); DrawWorld(yRot); // Now draw a cylinder representing the viewer M3DVector4f vLightTransformed; modelViewMatrix.GetMatrix(mMirrorView); m3dTransformVector4(vLightTransformed, vLightPos, mMirrorView); modelViewMatrix.Translate(vCameraPos[0],vCameraPos[1]-0.8f,vCameraPos[2]-1.0f); modelViewMatrix.Rotate(-90.0f, 1.0f, 0.0f, 0.0f); shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, modelViewMatrix.GetMatrix(), transformPipeline.GetProjectionMatrix(), vLightTransformed, vBlue, 0); cylinderBatch.Draw(); modelViewMatrix.PopMatrix(); // Reset FBO. Draw world again from the real cameras perspective glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glDrawBuffers(1, windowBuff); glViewport(0, 0, screenWidth, screenHeight); modelViewMatrix.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewMatrix.MultMatrix(mCamera); glBindTexture(GL_TEXTURE_2D, textures[0]); // Marble glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeline.GetModelViewProjectionMatrix(), vWhite, 0); floorBatch.Draw(); DrawWorld(yRot); // Now draw the mirror surfaces modelViewMatrix.PushMatrix(); modelViewMatrix.Translate(0.0f, -0.4f, -5.0f); if(vCameraPos[2] > -5.0) { glBindTexture(GL_TEXTURE_2D, mirrorTexture); // Reflection shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, transformPipeline.GetModelViewProjectionMatrix(), 0); } else { // If the camera is behind the mirror, just draw black shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vBlack); } mirrorBatch.Draw(); shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vGrey); mirrorBorderBatch.Draw(); modelViewMatrix.PopMatrix(); modelViewMatrix.PopMatrix(); // Do the buffer Swap glutSwapBuffers(); // Do it again glutPostRedisplay(); }
/////////////////////////////////////////////////////////////////////////////// // Render a frame. The owning framework is responsible for buffer swaps, // flushes, etc. void RenderScene(void) { // Bind the FBO with multisample buffers glBindFramebuffer(GL_DRAW_FRAMEBUFFER, msFBO); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // User selected order independant transparency if (mode == USER_OIT) { // Use OIT, setup sample masks glSampleMaski(0, 0x01); glEnable(GL_SAMPLE_MASK); // Prevent depth test from culling covered surfaces glDepthFunc(GL_ALWAYS); } modelViewMatrix.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewMatrix.MultMatrix(mCamera); modelViewMatrix.PushMatrix(); modelViewMatrix.Translate(0.0f, -0.4f, -4.0f); modelViewMatrix.Rotate(worldAngle, 0.0, 1.0, 0.0); // Draw the background and disk to the first sample modelViewMatrix.PushMatrix(); modelViewMatrix.Translate(0.0f, 3.0f, 0.0f); modelViewMatrix.Rotate(90.0, 1.0, 0.0, 0.0); modelViewMatrix.Rotate(90.0, 0.0, 0.0, 1.0); glBindTexture(GL_TEXTURE_2D, textures[1]); shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, transformPipeline.GetModelViewProjectionMatrix(), 0); bckgrndCylBatch.Draw(); modelViewMatrix.PopMatrix(); modelViewMatrix.Translate(0.0f, -0.3f, 0.0f); modelViewMatrix.PushMatrix(); modelViewMatrix.Rotate(90.0, 1.0, 0.0, 0.0); shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vGrey); diskBatch.Draw(); modelViewMatrix.PopMatrix(); modelViewMatrix.Translate(0.0f, 0.1f, 0.0f); // User selected blending if (mode == USER_BLEND) { // Setup blend state glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); switch (blendMode) { case 1: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); break; case 2: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA); break; case 3: glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); break; case 4: glBlendFunc(GL_SRC_ALPHA, GL_ONE); break; case 5: glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR); break; case 6: glBlendFuncSeparate(GL_SRC_ALPHA, GL_DST_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); break; case 7: glBlendFuncSeparate(GL_SRC_COLOR, GL_DST_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); break; default: glDisable(GL_BLEND); } } // Now draw the glass pieces DrawWorld(); modelViewMatrix.PopMatrix(); modelViewMatrix.PopMatrix(); // Clean up all state glDepthFunc(GL_LEQUAL); glDisable(GL_BLEND); glDisable(GL_SAMPLE_MASK); glSampleMaski(0, 0xffffffff); // Resolve multisample buffer projectionMatrix.PushMatrix(); projectionMatrix.LoadMatrix(orthoMatrix); modelViewMatrix.PushMatrix(); modelViewMatrix.LoadIdentity(); // Setup and Clear the default framebuffer glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glViewport(0, 0, screenWidth, screenHeight); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (mode == USER_OIT) SetupOITResolveProg(); else if (mode == USER_BLEND) SetupResolveProg(); // Draw a full-size quad to resolve the multisample surfaces screenQuad.Draw(); modelViewMatrix.PopMatrix(); projectionMatrix.PopMatrix(); // Reset texture state glEnable(GL_DEPTH_TEST); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0); // Do the buffer Swap glutSwapBuffers(); // Do it again glutPostRedisplay(); }
/////////////////////////////////////////////////////////////////////////////// // Render a frame. The owning framework is responsible for buffer swaps, // flushes, etc. void RenderScene(void) { static CStopWatch animationTimer; static float totalTime = 6; // To go back and forth static float halfTotalTime = totalTime/2; float seconds = animationTimer.GetElapsedSeconds() * speedFactor; float xPos = 0; // Calculate the next postion of the moving object // First perform a mod-like operation on the time as a float while(seconds > totalTime) seconds -= totalTime; // Move object position, if it's gone half way across // start bringing it back if(seconds < halfTotalTime) xPos = seconds -halfTotalTime*0.5f; else xPos = totalTime - seconds -halfTotalTime*0.5f; // First draw world to screen modelViewMatrix.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewMatrix.MultMatrix(mCamera); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textures[0]); // Marble glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeline.GetModelViewProjectionMatrix(), vWhite, 0); floorBatch.Draw(); DrawWorld(0.0f, xPos); modelViewMatrix.PopMatrix(); if(bUsePBOPath) { #ifndef OPENGL_ES // First bind the PBO as the pack buffer, then read the pixels directly to the PBO glBindBuffer(GL_PIXEL_PACK_BUFFER, pixBuffObjs[0]); glReadPixels(0, 0, screenWidth, screenHeight, GL_RGB, GL_UNSIGNED_BYTE, NULL); glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); // Next bind the PBO as the unpack buffer, then push the pixels straight into the texture glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pixBuffObjs[0]); // Setup texture unit for new blur, this gets imcremented every frame glActiveTexture(GL_TEXTURE0+GetBlurTarget0() ); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, screenWidth, screenHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); #endif } else { // Grab the screen pixels and copy into local memory glReadPixels(0, 0, screenWidth, screenHeight, GL_RGB, GL_UNSIGNED_BYTE, pixelData); // Push pixels from client memory into texture // Setup texture unit for new blur, this gets imcremented every frame glActiveTexture(GL_TEXTURE0+GetBlurTarget0() ); #ifndef OPENGL_ES glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, screenWidth, screenHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, pixelData); #else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screenWidth, screenHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, pixelData); #endif } // Draw full screen quad with blur shader and all blur textures projectionMatrix.PushMatrix(); projectionMatrix.LoadIdentity(); projectionMatrix.LoadMatrix(orthoMatrix); modelViewMatrix.PushMatrix(); modelViewMatrix.LoadIdentity(); glDisable(GL_DEPTH_TEST); SetupBlurProg(); screenQuad.Draw(); glEnable(GL_DEPTH_TEST); modelViewMatrix.PopMatrix(); projectionMatrix.PopMatrix(); // Move to the next blur texture for the next frame AdvanceBlurTaget(); // Do the buffer Swap glutSwapBuffers(); // Do it again glutPostRedisplay(); UpdateFrameCount(); }
void CGodRaysView::Draw() { CMatRenderContextPtr pRenderContext(materials); extern bool s_bCanAccessCurrentView; s_bCanAccessCurrentView = true; // Setup the view. const CViewSetup* pViewSetup = view->GetViewSetup(); Setup(*pViewSetup); // Build a list of all the shit to render. BuildWorldRenderLists(true); BuildRenderableRenderLists(VIEW_MAIN); // Save off the current view information and create a // new 'blank' view. Frustum frustum; render->Push3DView(*this, 0, NULL, frustum); // Pass 1: Draw the sun glow overlays first. pRenderContext->ClearBuffers(true, true, true); if (m_pSun) { DrawSunGlowOverlay(m_pSun->m_GlowOverlay); DrawSunGlowOverlay(m_pSun->m_Overlay); } // Clear off the stencil buffer since we want the skybox // to persist. pRenderContext->ClearBuffers(false, false, true); // Enable the stencil buffer. SetupStencilBuffer(pRenderContext); // Disallow all writes except stencil. pRenderContext->OverrideAlphaWriteEnable(true, false); pRenderContext->OverrideColorWriteEnable(true, false); pRenderContext->OverrideDepthEnable(true, false); //Pass 2: Draw both the world geometry AND entities. m_DrawFlags = DF_RENDER_ABOVEWATER | DF_DRAW_ENTITITES; DrawWorld(0.0f); DrawOpaqueRenderables(DEPTH_MODE_NORMAL); // Enable writes again. pRenderContext->OverrideAlphaWriteEnable(false, true); pRenderContext->OverrideColorWriteEnable(false, true); pRenderContext->OverrideDepthEnable(false, true); // Pass 3: Clear stenciled area. pRenderContext->SetStencilCompareFunction(STENCILCOMPARISONFUNCTION_EQUAL); pRenderContext->SetStencilPassOperation(STENCILOPERATION_KEEP); pRenderContext->ClearBuffersObeyStencil(true, false); // Restore the previous view's settings. render->PopView(frustum); s_bCanAccessCurrentView = false; // Disable the stencil buffer now. pRenderContext->SetStencilEnable(false); // Release the render context. pRenderContext->Release(); }