Skip to content
Browse files

Draw backdrops and map previews with VBOs.

  • Loading branch information...
1 parent 9ef70b7 commit 591b00c0dfdeb180467818babd722f2f0a0c485c @perim perim committed Feb 11, 2013
Showing with 93 additions and 96 deletions.
  1. +1 −1 lib/ivis_opengl/piemode.cpp
  2. +88 −88 lib/ivis_opengl/screen.cpp
  3. +2 −3 lib/ivis_opengl/screen.h
  4. +2 −4 src/multiint.cpp
View
2 lib/ivis_opengl/piemode.cpp
@@ -111,7 +111,7 @@ void pie_ScreenFlip(int clearMode)
if (screen_GetBackDrop())
{
- screen_Upload(NULL, screen_getMapPreview());
+ screen_Display();
}
}
View
176 lib/ivis_opengl/screen.cpp
@@ -54,6 +54,8 @@ static char screendump_filename[PATH_MAX];
static bool screendump_required = false;
static GLuint backDropTexture = 0;
+static GLuint buffers[VBO_COUNT];;
+
static int preview_width = 0, preview_height = 0;
static Vector2i player_pos[MAX_PLAYERS];
static bool mappreview = false;
@@ -182,6 +184,10 @@ bool screenInitialise()
pie_Skybox_Init();
+ // Generate backdrop buffers
+ glGenBuffers(VBO_MINIMAL, buffers);
+ glGenTextures(1, &backDropTexture);
+
glErrors();
return true;
}
@@ -190,6 +196,9 @@ void screenShutDown(void)
{
pie_Skybox_Shutdown();
+ glDeleteBuffers(VBO_MINIMAL, buffers);
+ glDeleteTextures(1, &backDropTexture);
+
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
}
@@ -270,31 +279,27 @@ void screen_SetBackDropFromFile(const char* filename)
// Otherwise WZ will think it is still loaded and not load it again
pie_SetTexturePage(TEXPAGE_EXTERN);
- if( strcmp(extension,".png") == 0 )
+ if (strcmp(extension, ".png") == 0)
{
- if (iV_loadImage_PNG( filename, &image ) )
+ if (iV_loadImage_PNG(filename, &image))
{
- if (backDropTexture == 0)
- glGenTextures(1, &backDropTexture);
-
glBindTexture(GL_TEXTURE_2D, backDropTexture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
- image.width, image.height,
- 0, iV_getPixelFormat(&image), GL_UNSIGNED_BYTE, image.bmp);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width, image.height,
+ 0, iV_getPixelFormat(&image), GL_UNSIGNED_BYTE, image.bmp);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
-
iV_unloadImage(&image);
+ screen_Upload(NULL);
}
- return;
}
else
+ {
debug(LOG_ERROR, "Unknown extension \"%s\" for image \"%s\"!", extension, filename);
+ }
}
-//===================================================================
void screen_StopBackDrop(void)
{
@@ -311,14 +316,68 @@ bool screen_GetBackDrop(void)
return bBackDrop;
}
+void screen_Display()
+{
+ pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_OFF);
+
+ // Make sure the current texture page is reloaded after we are finished
+ // Otherwise WZ will think it is still loaded and not load it again
+ pie_SetTexturePage(TEXPAGE_EXTERN);
+ glBindTexture(GL_TEXTURE_2D, backDropTexture);
+
+ // Draw backdrop
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glBindBuffer(GL_ARRAY_BUFFER, buffers[VBO_TEXCOORD]); glTexCoordPointer(2, GL_FLOAT, 0, NULL);
+ glBindBuffer(GL_ARRAY_BUFFER, buffers[VBO_VERTEX]); glVertexPointer(2, GL_FLOAT, 0, NULL);
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glErrors();
+
+ if (mappreview)
+ {
+ int s1 = screenWidth / preview_width;
+ int s2 = screenHeight / preview_height;
+ int scale = MIN(s1, s2);
+ int w = preview_width * scale;
+ int h = preview_height * scale;
+
+ for (int i = 0; i < MAX_PLAYERS; i++)
+ {
+ int x = player_pos[i].x;
+ int y = player_pos[i].y;
+ char text[5];
+
+ if (x == 0x77777777)
+ {
+ continue;
+ }
+
+ x = screenWidth / 2 - w / 2 + x * scale;
+ y = screenHeight / 2 - h / 2 + y * scale;
+ ssprintf(text, "%d", i);
+ iV_SetFont(font_large);
+ iV_SetTextColour(WZCOL_BLACK);
+ iV_DrawText(text, x - 1, y - 1);
+ iV_DrawText(text, x + 1, y - 1);
+ iV_DrawText(text, x - 1, y + 1);
+ iV_DrawText(text, x + 1, y + 1);
+ iV_SetTextColour(WZCOL_WHITE);
+ iV_DrawText(text, x, y);
+ }
+ }
+ pie_SetDepthBufferStatus(DEPTH_CMP_LEQ_WRT_ON);
+}
+
//******************************************************************
//slight hack to display maps (or whatever) in background.
//bitmap MUST be (BACKDROP_HACK_WIDTH * BACKDROP_HACK_HEIGHT) for now.
-void screen_Upload(const char *newBackDropBmp, bool preview)
+void screen_Upload(const char *newBackDropBmp)
{
- static bool processed = false;
- int x1 = 0, x2 = screenWidth, y1 = 0, y2 = screenHeight, i, scale = 0, w = 0, h = 0;
- float tx = 1, ty = 1;
+ int x1 = 0, x2 = screenWidth, y1 = 0, y2 = screenHeight, scale = 0, w = 0, h = 0;
+ GLfloat tx = 1, ty = 1;
const float aspect = screenWidth / (float)screenHeight, backdropAspect = 4 / (float)3;
if (aspect < backdropAspect)
@@ -334,43 +393,20 @@ void screen_Upload(const char *newBackDropBmp, bool preview)
y2 -= offset;
}
- if(newBackDropBmp != NULL)
+ if (newBackDropBmp) // preview
{
- if (processed) // lets free a texture when we use a new one.
- {
- glDeleteTextures( 1, &backDropTexture );
- }
-
- glGenTextures(1, &backDropTexture);
- pie_SetTexturePage(TEXPAGE_NONE);
+ pie_SetTexturePage(TEXPAGE_EXTERN);
glBindTexture(GL_TEXTURE_2D, backDropTexture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
- BACKDROP_HACK_WIDTH, BACKDROP_HACK_HEIGHT,
- 0, GL_RGB, GL_UNSIGNED_BYTE, newBackDropBmp);
-
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, BACKDROP_HACK_WIDTH, BACKDROP_HACK_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, newBackDropBmp);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
- processed = true;
- }
-
- pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_OFF);
-
- // Make sure the current texture page is reloaded after we are finished
- // Otherwise WZ will think it is still loaded and not load it again
- pie_SetTexturePage(TEXPAGE_EXTERN);
- glBindTexture(GL_TEXTURE_2D, backDropTexture);
- glColor3f(1, 1, 1);
-
- if (preview)
- {
- int s1, s2;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- s1 = screenWidth / preview_width;
- s2 = screenHeight / preview_height;
+ int s1 = screenWidth / preview_width;
+ int s2 = screenHeight / preview_height;
scale = MIN(s1, s2);
w = preview_width * scale;
@@ -383,48 +419,17 @@ void screen_Upload(const char *newBackDropBmp, bool preview)
tx = preview_width / (float)BACKDROP_HACK_WIDTH;
ty = preview_height / (float)BACKDROP_HACK_HEIGHT;
}
- else
- {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- }
- glBegin(GL_TRIANGLE_STRIP);
- glTexCoord2f(0, 0);
- glVertex2f(x1, y1);
- glTexCoord2f(tx, 0);
- glVertex2f(x2, y1);
- glTexCoord2f(0, ty);
- glVertex2f(x1, y2);
- glTexCoord2f(tx, ty);
- glVertex2f(x2, y2);
- glEnd();
-
- if (preview)
- {
- for (i = 0; i < MAX_PLAYERS; i++)
- {
- int x = player_pos[i].x;
- int y = player_pos[i].y;
- char text[5];
+ // Generate coordinates and put them into VBOs
+ GLfloat texcoords[8] = { 0.0f, 0.0f, tx, 0.0, 0.0f, ty, tx, ty };
+ GLfloat vertices[8] = { x1, y1, x2, y1, x1, y2, x2, y2 };
+ glBindBuffer(GL_ARRAY_BUFFER, buffers[VBO_TEXCOORD]);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(texcoords), texcoords, GL_STATIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, buffers[VBO_VERTEX]);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
- if (x == 0x77777777)
- continue;
-
- x = screenWidth / 2 - w / 2 + x * scale;
- y = screenHeight / 2 - h / 2 + y * scale;
- ssprintf(text, "%d", i);
- iV_SetFont(font_large);
- iV_SetTextColour(WZCOL_BLACK);
- iV_DrawText(text, x - 1, y - 1);
- iV_DrawText(text, x + 1, y - 1);
- iV_DrawText(text, x - 1, y + 1);
- iV_DrawText(text, x + 1, y + 1);
- iV_SetTextColour(WZCOL_WHITE);
- iV_DrawText(text, x, y);
- }
- }
- pie_SetDepthBufferStatus(DEPTH_CMP_LEQ_WRT_ON);
+ glErrors();
}
void screen_enableMapPreview(int width, int height, Vector2i *playerpositions)
@@ -445,11 +450,6 @@ void screen_disableMapPreview(void)
mappreview = false;
}
-bool screen_getMapPreview(void)
-{
- return mappreview;
-}
-
// Screenshot code goes below this
static const unsigned int channelsPerPixel = 3;
View
5 lib/ivis_opengl/screen.h
@@ -49,19 +49,18 @@ extern void screen_SetBackDropFromFile(const char* filename);
extern void screen_StopBackDrop(void);
extern void screen_RestartBackDrop(void);
extern bool screen_GetBackDrop(void);
-extern void screen_Upload(const char *newBackDropBmp, bool preview);
+extern void screen_Upload(const char *newBackDropBmp);
+void screen_Display();
/* screendump */
extern void screenDumpToDisk(const char* path);
extern int wz_texture_compression;
-
extern void screenDoDumpToDiskIfRequired(void);
void screen_enableMapPreview(int width, int height, Vector2i *playerpositions);
void screen_disableMapPreview(void);
-bool screen_getMapPreview(void);
void screen_EnableMissingFunctions();
struct OPENGL_DATA
View
6 src/multiint.cpp
@@ -433,7 +433,7 @@ static void loadEmptyMapPreview()
screen_enableMapPreview(ex, ey, playerpos);
- screen_Upload(imageData, true);
+ screen_Upload(imageData);
free(imageData);
}
@@ -595,7 +595,7 @@ void loadMapPreview(bool hideInterface)
screen_enableMapPreview(mapWidth, mapHeight, playerpos);
- screen_Upload(imageData, true);
+ screen_Upload(imageData);
free(imageData);
@@ -3641,8 +3641,6 @@ void frontendMultiMessages(void)
{
setLobbyError(KICK_TYPE);
stopJoining();
- //screen_RestartBackDrop();
- //changeTitleMode(TITLE);
pie_LoadBackDrop(SCREEN_RANDOMBDROP);
debug(LOG_ERROR, "You have been kicked, because %s ", reason);
}

0 comments on commit 591b00c

Please sign in to comment.
Something went wrong with that request. Please try again.