From 066d9232d166b6ba990a87b45e1d30366163c4a1 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Tue, 15 Jul 2008 21:09:36 +0100 Subject: [PATCH] Optimise surface rendering --- src/OpenGL.cpp | 4 +++- src/Surface.cpp | 35 +++++++++++++++++++++++++---------- src/Surface.hpp | 8 +++++++- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/OpenGL.cpp b/src/OpenGL.cpp index c757804..9bdf39b 100644 --- a/src/OpenGL.cpp +++ b/src/OpenGL.cpp @@ -131,7 +131,7 @@ void OpenGL::Run() void OpenGL::DrawGLScene() { // Clear the screen - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); // Render the scene @@ -290,10 +290,12 @@ bool OpenGL::InitGL() glShadeModel(GL_SMOOTH); // Enable smooth shading glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black background glClearDepth(1.0f); // Depth buffer setup + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Basic blending function glEnable(GL_ALPHA_TEST); // Enable alpha testing glAlphaFunc(GL_GREATER, 0.0); // Alpha testing function glDisable(GL_NORMALIZE); + glDisable(GL_DEPTH_TEST); // All went OK return true; diff --git a/src/Surface.cpp b/src/Surface.cpp index 4a885c2..22f2a04 100644 --- a/src/Surface.cpp +++ b/src/Surface.cpp @@ -49,18 +49,16 @@ void Surface::Generate(int surftex, LandingPadList &pads) delete[] surface; int nPolys = viewport->GetLevelWidth()/SURFACE_SIZE; - surface = new Poly[nPolys]; + surface = new SurfaceSection[nPolys]; + + texidx = surftex; int texloop = 0; for (int i = 0; i < nPolys; i++) { - surface[i].pointcount = 4; - surface[i].xpos = i * SURFACE_SIZE; - surface[i].ypos = viewport->GetLevelHeight() - MAX_SURFACE_HEIGHT; - surface[i].uTexture = surfTexture[surftex]->GetGLTexture(); - surface[i].texX = ((float)texloop)/10; + surface[i].texX = ((double)texloop)/10.0; if (texloop++ == 10) texloop = 0; - surface[i].texwidth = 0.1f; + surface[i].texwidth = 0.1; surface[i].points[0].x = 0; surface[i].points[0].y = MAX_SURFACE_HEIGHT; @@ -123,11 +121,28 @@ void Surface::Display() if (right > max) right = max; + glDisable(GL_BLEND); + glEnable(GL_TEXTURE_2D); + glColor4d(1.0, 1.0, 1.0, 1.0); + glBindTexture(GL_TEXTURE_2D, surfTexture[texidx]->GetGLTexture()); + for (int i = left; i < right; i++) { - surface[i].xpos = i*SURFACE_SIZE - viewport->GetXAdjust(); - surface[i].ypos = viewport->GetLevelHeight() + double xpos = i*SURFACE_SIZE - viewport->GetXAdjust(); + double ypos = viewport->GetLevelHeight() - viewport->GetYAdjust() - MAX_SURFACE_HEIGHT; - OpenGL::GetInstance().Draw(&surface[i]); + + glLoadIdentity(); + glTranslated(xpos, ypos, 0.0); + glBegin(GL_QUADS); + glTexCoord2d(surface[i].texX, 0.0); + glVertex2i(surface[i].points[0].x, surface[i].points[0].y); + glTexCoord2d(surface[i].texX, 1.0); + glVertex2i(surface[i].points[1].x, surface[i].points[1].y); + glTexCoord2d(surface[i].texX + surface[i].texwidth, 1.0); + glVertex2i(surface[i].points[2].x, surface[i].points[2].y); + glTexCoord2d(surface[i].texX + surface[i].texwidth, 0.0); + glVertex2i(surface[i].points[3].x, surface[i].points[3].y); + glEnd(); } } diff --git a/src/Surface.hpp b/src/Surface.hpp index 968b3ff..0ce38f5 100644 --- a/src/Surface.hpp +++ b/src/Surface.hpp @@ -42,8 +42,14 @@ public: private: static Texture *surfTexture[NUM_SURF_TEX]; + int texidx; Viewport *viewport; - Poly *surface; + + struct SurfaceSection { + double texX, texwidth; + Point points[4]; + }; + SurfaceSection *surface; }; #endif -- 2.39.2