bool Renderer::Create( double width, double height ) { SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); m_glcontext = SDL_GL_CreateContext( m_Window.GetSDLWindow() ); if (m_glcontext == nullptr) return false; //Initialize Projection Matrix glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho(0.0, width, height, 0.0, 1.0, -1.0); if (!CheckGLError()) return false; //Initialize Modelview Matrix glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); if (!CheckGLError()) return false; glClearColor(m_BackgroundColor.r, m_BackgroundColor.g, m_BackgroundColor.b, m_BackgroundColor.a); ClearBackBuffer(); if (!CheckGLError()) return false; //Enable texturing glEnable( GL_TEXTURE_2D ); return true; }
bool ClientLobbyState::Draw(FlexKit::EngineCore* core, FlexKit::UpdateDispatcher& dispatcher, double dT, FlexKit::FrameGraph& frameGraph) { auto currentRenderTarget = GetCurrentBackBuffer(&core->Window); ClearVertexBuffer (frameGraph, client->base->vertexBuffer); ClearVertexBuffer (frameGraph, client->base->textBuffer); ClearBackBuffer (frameGraph, { 0.0f, 0.0f, 0.0f, 0.0f }); LobbyScreenDrawDesc Desc; Desc.allocator = core->GetTempMemory(); Desc.constantBuffer = client->base->constantBuffer; Desc.vertexBuffer = client->base->vertexBuffer; Desc.textBuffer = client->base->textBuffer; Desc.renderTarget = currentRenderTarget; screen.Draw(Desc, dispatcher, frameGraph); FlexKit::DrawMouseCursor( framework->MouseState.NormalizedScreenCord, { 0.05f, 0.05f }, client->base->vertexBuffer, client->base->constantBuffer, currentRenderTarget, core->GetTempMemory(), &frameGraph); return true; }
void Game::Draw() { ClearBackBuffer(); MainRenderPass.Render(); SwapBuffers(); }
void Renderer::Present() { if (m_pRenderer) { //Update screen SDL_RenderPresent(m_pRenderer); //Clear screen ready for next frame ClearBackBuffer(); } }
void Renderer::Present() { if (m_glcontext) { //Update screen SDL_GL_SwapWindow( m_Window.GetSDLWindow() ); //Clear screen ready for next frame ClearBackBuffer(); } }
bool Renderer::Create(SDL_Window* pWindow, Uint32 flags /*= SDL_RENDERER_ACCELERATED*/, int index /*= -1*/) { if (!pWindow) return false; Release(); m_pRenderer = SDL_CreateRenderer(pWindow, index, flags); if (m_pRenderer == nullptr) return false; ClearBackBuffer(); return true; }
void MCBitmap::Import(CImage &img) { ClearBackBuffer(); { ImportHelper help(this, img, true); BYTE top[16]; int num = help.CountTopColorsPerCell(top); *background = top[0]; help.ReduceColors(4, top, num < 1 ? num : 1); } *border = GuessBorderColor(); }
void UpdateSimulation(void) { double dt = _TIMESTEP; int i; double f, dl; Vector pt1, pt2; int j; Vector r; Vector F; Vector v1, v2, vr; if (FrameCounter >= _RENDER_FRAME_COUNT) { ClearBackBuffer(); DrawLine(0, _WINHEIGHT - _GROUND_PLANE, _WINWIDTH, _WINHEIGHT - _GROUND_PLANE, 3, RGB(0, 0, 0)); DrawObstacles(); } for (i = 0; i < _NUM_OBJECTS; i++) { Objects[i].vSprings.x = 0; Objects[i].vSprings.y = 0; Objects[i].vSprings.z = 0; } for (i = 0; i < _NUM_SPRINGS; i++) { j = Springs[i].End1; pt1 = Objects[j].vPosition; v1 = Objects[j].vVelocity; j = Springs[i].End2; pt2 = Objects[j].vPosition; v2 = Objects[j].vVelocity; vr = v2 - v1; r = pt2 - pt1; dl = r.Magnitude() - Springs[i].InitialLength; f = Springs[i].k* dl; r.Normalize(); F = (r*f) + (Springs[i].d*(vr*r))*r; j = Springs[i].End1; if (Objects[j].bLocked == false) Objects[j].vSprings += F; j = Springs[i].End2; if (Objects[j].bLocked == false) Objects[j].vSprings -= F; } for (i = 0; i < _NUM_OBJECTS; i++) { Objects[i].bCollision = CheckForCollisions(&(Objects[i])); Objects[i].CalcLoads(); Objects[i].UpdateBodyEuler(dt); if (FrameCounter >= _RENDER_FRAME_COUNT) { Objects[i].Draw(); if (i < _NUM_OBJECTS - 1) Objects[i].DrawObjectLine(Objects[i + 1].vPosition); } if (Objects[i].vPosition.x > _WINWIDTH) Objects[i].vPosition.x = 0; if (Objects[i].vPosition.x < 0) Objects[i].vPosition.x = _WINWIDTH; if (Objects[i].vPosition.y < 0) Objects[i].vPosition.y = _WINHEIGHT; } if (FrameCounter >= _RENDER_FRAME_COUNT) { CopyBackBufferToWindow(); FrameCounter = 0; } else FrameCounter++; }
MyDrawEngine::MyDrawEngine(int width, int height, int bitsPerPixel, HWND hwnd, bool bFullScreen) { HRESULT err; DWORD CoopLevel; //Hack - I reckon a boolean needs to be passed into GameInit() from wincode.cpp //which is then passed into the MyDrawEngine constructor, rather than an extern! - Dan mbFullScreen = bFullScreen; // Set attributes ZeroMemory(&ddsd, sizeof(ddsd)); bytesPerPixel = bitsPerPixel/8; lpBackBuffer = NULL; lpPrimarySurface = NULL; lpClipper = NULL; memoryPitch = 0; screenHeight = height; screenWidth = width; videoAddress = NULL; mHwnd = hwnd; //Configure cooperative mode flags if(mbFullScreen) { CoopLevel = DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT; } else { CoopLevel = DDSCL_NORMAL; } // to do: add defensive programming err=DirectDrawCreateEx(0,(void**)&lpdd,IID_IDirectDraw7,0); if (FAILED(err)) { ErrorLogger::Writeln("Could not connect to IDirectDraw7"); ErrorLogger::Writeln(ErrorString(err)); lpdd=NULL; return; // No point going any further } // set cooperation level err=lpdd->SetCooperativeLevel(hwnd, CoopLevel); if (FAILED(err)) { ErrorLogger::Writeln("Could not set cooperative level"); ErrorLogger::Writeln(ErrorString(err)); lpdd->Release(); lpdd=NULL; return; // No point going any further } // set display mode if( mbFullScreen ) { err=lpdd->SetDisplayMode(width,height,bytesPerPixel*8,0,0); if (FAILED(err)) { ErrorLogger::Writeln("Could not set display mode"); ErrorLogger::Writeln(ErrorString(err)); lpdd->Release(); lpdd=NULL; return; // No point going any further } } // Create the primary surface // First, make out an "order form" for the surface ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); if( mbFullScreen ) { ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; } else { ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; } // Now get the primarySurface err=lpdd->CreateSurface(&ddsd,&lpPrimarySurface,NULL); if(FAILED(err)) { ErrorLogger::Writeln("Failed to create primary surface"); ErrorLogger::Writeln(ErrorString(err)); lpdd->Release(); lpdd=NULL; return; // No point going any further } // --- Now get the back buffer --- if(mbFullScreen) { // Generic surface capabilities struct DDSCAPS2 ddsCaps; //Clear it ZeroMemory(&ddsCaps, sizeof(ddsCaps)); ddsCaps.dwCaps = DDSCAPS_BACKBUFFER | DDSCAPS_FLIP; err=lpPrimarySurface->GetAttachedSurface(&ddsCaps,&lpBackBuffer); } else { DDSURFACEDESC2 desc; ZeroMemory(&desc, sizeof(DDSURFACEDESC2)); desc.dwSize = sizeof(DDSURFACEDESC2); desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; desc.dwWidth = width; desc.dwHeight = height; err = lpdd->CreateSurface(&desc, &lpBackBuffer, NULL); } if(FAILED(err)) { ErrorLogger::Writeln("Failed to obtain back surface"); ErrorLogger::Writeln(ErrorString(err)); lpClipper->Release(); lpPrimarySurface->Release(); lpdd->Release(); lpdd=NULL; return; // No point going any further } //Create a clipper for the back buffer! tagRECT clipArea; clipArea.top = 0; clipArea.left = 0; clipArea.bottom = height; clipArea.right = width; // Set clipper for back buffer surface // Chris - this function should be made to be more generic, // so that it can be applied to any direct draw surface SetClipper(1, &clipArea); // clear primary and secondary surfaces ClearBackBuffer(); Flip(); ClearBackBuffer(); }