Applied same clipping scheme (+ forced 2^n x 2^n texture) for splash screen as for menus BG images

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@1958 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 811bdbdec295b881a124b13a0e5288feedd31cb9
Former-commit-id: 688b865742a73783dec68a4098a3f16961eeb5f1
This commit is contained in:
pouillot 2009-12-07 21:45:50 +00:00
parent 82ef6228a8
commit 772fb94919

View file

@ -34,7 +34,8 @@
#include "splash.h"
#include "mainmenu.h"
static int s_imgWidth, s_imgHeight;
static int s_imgWidth, s_imgHeight; // Real image size (from image file).
static int s_imgPow2Width, s_imgPow2Height; // Smallest possible containing 2^N x 2^P.
static GLuint s_texture = 0;
static int SplashDisplaying;
static char buf[1024];
@ -128,30 +129,39 @@ static void splashDisplay( void )
if (s_texture != 0)
{
GLfloat tx1 = 0.0f, tx2 = 1.0f, ty1 = 0.0f, ty2 = 1.0f;
// Prepare texture display.
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, s_texture);
// Compute texture coordinates to ensure proper unskewed/unstretched display of
// image content.
//tdble rfactor = (float)(s_imgWidth*ViewH)/(float)(s_imgHeight*ViewW);
tdble rfactor = (16.0f*ViewH)/(10.0f*ViewW);
// Compute the initial width of the right area and the height of the bottom area
// of the texture that will not be displayed
// (We display only the top left rectangle of the quad texture
// that corresponds to the original image).
GLfloat tx1 = 0.0f;
GLfloat tx2 = s_imgWidth / (GLfloat)s_imgPow2Width;
if (rfactor >= 1.0f)
{
// Aspect ratio of view is smaller than 16:10, "cut off" sides
tdble tdx = (1.0f-1.0f/rfactor)/2.0f;
GLfloat ty1 = 1.0f - s_imgHeight / (GLfloat)s_imgPow2Height;
GLfloat ty2 = 1.0;
// Compute the width/height of the symetrical left/right / top/bottom
// areas of original image that will need to be clipped
// in order to keep its aspect ratio.
const GLfloat rfactor = s_imgWidth * (GLfloat)ViewH / s_imgHeight / (GLfloat)ViewW;
if (rfactor >= 1.0f) {
// If aspect ratio of view is smaller than image's one, "cut off" sides.
const GLfloat tdx = s_imgWidth * (rfactor - 1.0f) / s_imgPow2Width / 2.0f;
tx1 += tdx;
tx2 -= tdx;
}
else
{
// Aspect ratio of view is larger than 16:10, "cut off" top and bottom
tdble tdy = (1.0f-rfactor)/2.0f;
} else {
// If aspect ratio of view is larger than image's one,
// "cut off" top and bottom.
const GLfloat tdy = s_imgHeight * (1.0f / rfactor - 1.0f) / s_imgPow2Height / 2.0f;
ty1 += tdy;
ty2 -= tdy;
}
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, s_texture);
// Display texture.
glBegin(GL_QUADS);
glTexCoord2f(tx1, ty1); glVertex3f(0.0, 0.0, 0.0);
glTexCoord2f(tx1, ty2); glVertex3f(0.0, ScrH, 0.0);
@ -214,11 +224,11 @@ int SplashScreen(void)
sprintf(buf, "%s%s", GetLocalDir(), GFSCR_CONF_FILE);
handle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
screen_gamma = (float)GfParmGetNum(handle, GFSCR_SECT_PROP, GFSCR_ATT_GAMMA, (char*)NULL, 2.0);
GLbyte *tex = (GLbyte*)GfImgReadPng(filename, &s_imgWidth, &s_imgHeight, screen_gamma, 0, 0);
GLbyte *tex = (GLbyte*)GfImgReadPng(filename, &s_imgWidth, &s_imgHeight, screen_gamma, &s_imgPow2Width, &s_imgPow2Height);
if (!tex)
{
GfParmReleaseHandle(handle);
GfTrace("Couldn't read %s\n", filename);
GfTrace("Couldn't load splash screen image %s\n", filename);
return -1;
}
@ -226,7 +236,7 @@ int SplashScreen(void)
glBindTexture(GL_TEXTURE_2D, s_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, s_imgWidth, s_imgHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *)(tex));
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, s_imgPow2Width, s_imgPow2Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *)(tex));
free(tex);
glutDisplayFunc(splashDisplay);