Originally Posted by
CrazyNorman
Let's say you have a 640x480 texture. You would load it, then create a blank 1024x1024 texture (the smallest power of two <= the textures largest dimension). Then, blit your texture to the blank texture. Use the 1024x1024 one with OpenGL. You're UV coordinates for a rectangle would be
(0,0)
(0,480/1024)
(640/1024,480/1024)
(640/1024,0)
Of course, this works with textures of any width and height.
Ok, I'm trying to do this but I'm unsure how to go about it...
I havent really been using OpenGL for too long, so I'm falling back on some GLAux code from NeHe's tut...
Here's some code that's relevant:
Code:
GLuint Tiles[255]; // Holds all our tiles' textures
GLuint StartScr; // Holds our start-screen's texture
AUX_RGBImageRec* LoadBMP(char *Filename) // Load a bitmap from a file as a texture
{
FILE* File; // File handle
if(!Filename) // Check we've been given a filename
{
return NULL; // Dont want to open nothing, so return
}
File=fopen(Filename,"r"); // Make sure the file exists
if(File) // Check it exists
{
fclose(File); // Close the file
return auxDIBImageLoadA(Filename); // Load the bitmap and return pointer
}
MessageBoxA(hWnd,"File not found",Filename,MB_OK|MB_ICONSTOP);
return NULL; // If all failed, return NULL;
}
int LoadGLTextures() // Load the textures
{
int Status=0; // Status indicator
AUX_RGBImageRec* TextureImage[1]; // Holds storage for the textures
memset(TextureImage,0,sizeof(void *)*1); // Fill with null
// Load Start Screen texture
if(TextureImage[0]=LoadBMP("Graphics\\Splash.bmp"))
{
Status=TRUE;
glGenTextures(1,&StartScr); // Generate a texture from the bitmap
glBindTexture(GL_TEXTURE_2D, StartScr); // Bind the texture as 2D
// Generate texture properly
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
}
if(TextureImage[0]) // Does Texture Exist
{
if(TextureImage[0]->data) // Does The Texture Data Exist
{
free(TextureImage[0]->data); // Release the data
}
free(TextureImage[0]); // Release the texture
}
return Status;
}
This code loads the bitmap and creates a texture out of it, which it then assigns an ID in the Tiles (or SplashScr), allowing it to use my Tile Map to easily display the tiles.
Code:
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(0.0f,0.0f,-3.5f); // Set our depth into the screen
if(resetAmbience==0) BeginAmbience(); // If we need to initiate the sound, do so
if(startScreen==1) // If we need to display the start screen
{
glBindTexture(GL_TEXTURE_2D,StartScr); // Bind texture ready for display
glBegin(GL_QUADS);
glTexCoord2f(0.0f,0.0f); // Bottom left
glVertex3f(-1.0f,-1.0f,1.0f); //
glTexCoord2f(1.0f,0.0f); // Bottom right
glVertex3f(1.0f,-1.0f,1.0f); //
glTexCoord2f(1.0f,1.0f); // Top right
glVertex3f(1.0f,1.0f,1.0f); //
glTexCoord2f(0.0f,1.0f); // Top left
glVertex3f(-1.0f,1.0f,1.0f); //
glEnd();
}
return TRUE; // Everything Went OK
}
Here's yeah, comments explain it all...
This is the last code that works, and draws my "Square" Start Screen, which is 512x512, but I need to draw the 640x480 one, and I've tried fiddling around with the co-ordinates and getting them into 4:3 ratio but that doesnt seem to be working =|