alright,
well since my fonts failed, I''ve decided to make up my own fonts class which reads in a bitmap that has fonts layed out in a grid. Now all I want to do is print a quad for each character in a string, that''s easy. But getting the texture right for the character is a nightmare. I''ve searched the depth of this forum and checked documentation on glTexCoord2f, but I still get confused.
The problem is this, for each character I must prtint out a quad which has only the letter in the bitmap on its quad face. This means getting texture co-ordinates for top, left, right, bottom of this letter and using glTexCoord2f to sort out what part of the fonts bitmap I want on this quad, correct? Done that, but whenever the quad is displayed, the WHOLE font bitmap (not just the letter which I want) is wrapped across the quad THOUSANDS of times! wtf!!? So this means it looks realy corrupt and if you zoom really far into the quad you can see the whole font bitmap turning into shape.
Here is my code:
void Render ( Vector vPoint, Vector vRight, Vector vUp, int iTexStartX, int iTexStartY )
{
float fSize = ((float)m_wantedsize/2); // size from middle
Vector vNewPoint;
glPushMatrix();
// move to origin (?)
glTranslatef(vPoint.x,vPoint.y,vPoint.z);
// use font texture
glBindTexture(GL_TEXTURE_2D, m_texture[0]);
// use white colour
glColor3f(1.0f,1.0f,1.0f);
// texture points
float fTexTop = (float)(iTexStartY+m_fontheight);
float fTexBottom = (float)(iTexStartY);
float fTexLeft = (float)(iTexStartX);
float fTexRight = (float)(iTexStartX+m_fontwidth);
glBegin(GL_QUADS); // Build Quad
vNewPoint = vPoint + ((-(vRight + vUp)).Normalize())*fSize;
glTexCoord2f(fTexLeft,fTexBottom);
glVertex3fv((float*)vNewPoint); // Bottom Left
vNewPoint = vPoint + ((vRight - vUp).Normalize())*fSize;
glTexCoord2f(fTexRight,fTexBottom);
glVertex3fv((float*)vNewPoint); // Bottom Right
vNewPoint = vPoint + ((vRight + vUp).Normalize())*fSize;
glTexCoord2f(fTexRight,fTexTop);
glVertex3fv((float*)vNewPoint); // Top Right
vNewPoint = vPoint + ((vUp - vRight).Normalize())*fSize;
glTexCoord2f(fTexLeft,fTexTop);
glVertex3fv((float*)vNewPoint); // Top Left
glEnd();
// Done
glPopMatrix();
}
and this is how I load my texture...
void createFonts ()
{
found_texture = false; // Status Indicator
AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Textures
memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL
char bmp_filename[MAX_PATH];
sprintf(bmp_filename,"%s\\Data/fonts.bmp",winamp_folder);
if ( (TextureImage[0]=LoadBMP(bmp_filename)) != 0 ) // Load Particle Texture
{
found_texture=true; // Set The Status To TRUE
glGenTextures(1, &m_texture[0]); // Create One Texture
glBindTexture(GL_TEXTURE_2D, m_texture[0]);
// take WRAPPING out!
//glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
//glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
m_texwidth = TextureImage[0]->sizeX;
m_texheight = TextureImage[0]->sizeY;
glTexImage2D(GL_TEXTURE_2D, 0, 3, m_texwidth, m_texheight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, TextureImage[0]->data);
m_fontwidth = m_texwidth/16;
m_fontheight = m_texheight/16;
}
if (TextureImage[0]) // If Texture Exists
{
if (TextureImage[0]->data) // If Texture Image Exists
{
free(TextureImage[0]->data); // Free The Texture Image Memory
}
free(TextureImage[0]); // Free The Image Structure
}
}
Is there anything at all possibly wrong with that?
I think glTexCoord2f is doing something strange, is it only values from 0 to 1 that can go into glTexCoord2f as parameters?? (by reading aeverything no-one has ever mentioned this) but by reading gamedev''s opengl Game programming book I would have assumed so, I think maybe the value should be more than 1 if I want to shift the texture points, which is what I really want do do!!!
Thanks, and remember this has been wrecking my brain