/* Copyright (C) 1991-2001 and beyond by Bungie Studios, Inc. and the "Aleph One" developers. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. This license is contained in the file "COPYING", which is included with this source code; it is available online at http://www.gnu.org/licenses/gpl.html Overhead-Map OpenGL Class Implementation by Loren Petrich, August 3, 2000 Subclass of OverheadMapClass for doing rendering with OpenGL Code originally from OGL_Map.c; font handling is still MacOS-specific. [Notes from OGL_Map.c] This is for drawing the Marathon overhead map with OpenGL, because at large resolutions, the main CPU can be too slow for this. Much of this is cribbed from overhead_map_macintosh.c and translated into OpenGL form July 9, 2000: Complete this OpenGL renderer. I had to add a font-info cache, so as to avoid re-generating the fonts for every frame. The font glyphs and offsets are stored as display lists, which appears to be very efficient. July 16, 2000: Added begin/end pairs for line and polygon rendering; the purpose of these is to allow more efficient caching. Jul 17, 2000: Paths now cached and drawn as a single line strip per path. Lines now cached and drawn in groups with the same width and color; that has yielded a significant performance improvement. Same for the polygons, but with relatively little improvement. [End notes] Aug 6, 2000 (Loren Petrich): Added perimeter drawing to drawing commands for the player object; this guarantees that this object will always be drawn reasonably correctly Oct 13, 2000 (Loren Petrich) Converted the various lists into Standard Template Library vectors Jan 25, 2002 (Br'fin (Jeremy Parsons)): Added TARGET_API_MAC_CARBON for AGL.h */ #include #include #include "cseries.h" #include "OverheadMap_OGL.h" #include "map.h" #ifdef HAVE_OPENGL #ifdef HAVE_OPENGL # if defined (__APPLE__) && defined (__MACH__) # include # include # elif defined mac # include # include # else # include # include # endif #endif #ifdef mac # if defined(EXPLICIT_CARBON_HEADER) # include # else # include # endif #endif #define USE_VERTEX_ARRAYS // rgb_color straight to OpenGL static inline void SetColor(rgb_color& Color) {glColor3usv((unsigned short *)(&Color));} // Need to test this so as to find out when the color changes static inline bool ColorsEqual(rgb_color& Color1, rgb_color& Color2) { return ((Color1.red == Color2.red) && (Color1.green == Color2.green) && (Color1.blue == Color2.blue)); } #ifdef mac // Render context for aglUseFont(); defined in OGL_Render.c extern AGLContext RenderContext; #endif // For marking out the area to be blanked out when starting rendering; // these are defined in OGL_Render.cpp extern short ViewWidth, ViewHeight; void OverheadMap_OGL_Class::begin_overall() { // Blank out the screen // Do that by painting a black polygon glColor3f(0,0,0); glBegin(GL_POLYGON); glVertex2f(0,0); glVertex2f(0,ViewHeight); glVertex2f(ViewWidth,ViewHeight); glVertex2f(ViewWidth,0); glEnd(); /* #ifndef mac glEnable(GL_SCISSOR_TEST); // Don't erase the HUD #endif glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT); #ifndef mac glDisable(GL_SCISSOR_TEST); #endif */ // Here's for the overhead map glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glDisable(GL_ALPHA_TEST); glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); glDisable(GL_FOG); glLineWidth(1); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } void OverheadMap_OGL_Class::end_overall() { glEnableClientState(GL_TEXTURE_COORD_ARRAY); // Reset line width glLineWidth(1); } void OverheadMap_OGL_Class::begin_polygons() { // Polygons are rendered before lines, and use the endpoint array, // so both of them will have it set here. Using the compiled-vertex extension, // however, makes everything the same color :-P #if defined(USE_VERTEX_ARRAYS) // CB: Vertex arrays crash both Mesa and NVidia's GL implementation // (reason still to be determined) // ghs: this is because the texture coord array was enabled, I think // if there's still trouble, #undef USE_VERTEX_ARRAYS glVertexPointer(2,GL_SHORT,GetVertexStride(),GetFirstVertex()); #endif // Reset color defaults SavedColor.red = SavedColor.green = SavedColor.blue = 0; SetColor(SavedColor); // Reset cache to zero length PolygonCache.clear(); } void OverheadMap_OGL_Class::draw_polygon( short vertex_count, short *vertices, rgb_color& color) { // Test whether the polygon parameters have changed bool AreColorsEqual = ColorsEqual(color,SavedColor); // If any change, then draw the cached lines with the *old* parameters, // Set the new parameters if (!AreColorsEqual) { DrawCachedPolygons(); SavedColor = color; SetColor(SavedColor); } // Implement the polygons as triangle fans #if defined(USE_VERTEX_ARRAYS) for (int k=2; k>1); break; default: return; } // Set color and location SetColor(color); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glTranslatef(left_location.x,left_location.y,0); FontData.OGL_Render(text); glPopMatrix(); } void OverheadMap_OGL_Class::set_path_drawing(rgb_color& color) { SetColor(color); glLineWidth(1); } void OverheadMap_OGL_Class::draw_path( short step, // 0: first point world_point2d &location) { // At first step, reset the length if (step <= 0) PathPoints.clear(); // Add the point PathPoints.push_back(location); } void OverheadMap_OGL_Class::finish_path() { glVertexPointer(2,GL_SHORT,sizeof(world_point2d),&PathPoints.front()); glDrawArrays(GL_LINE_STRIP,0,(GLsizei)(PathPoints.size())); } #endif // def HAVE_OPENGL