Skip to main content
GameDev.net gamedev.net
🔒 Locked

rendering textures in oop structure - HELP!!

Started by SurreySnYder Jan 2, 2005 at 11:52 AM 5 replies 600+ views
Original Post
SurreySnYder
SurreySnYder
I have started writting a program that uses OOP object to contain different items to be drawn. However when ever i try to bind a texture to a surface, GL_QUAD, in this case, the texture does not get shown. I know the code is not the problem, and this is what confuses me, the code works when it is used in the same file as main(), and the call is done in a flat file procedual manner. However this is not doable as the program is going to be big, and require reuasability, and likely to have 100's of textures! I am sure i have just done some thing stupid, but i am stumped. There does not seem to be any code samples on the net that use this method of creating and binding textures outside of the main(). The use of objects to carry out all other primative creation is working fine, but i can put textures on them! Thank you for any assistance in this matter. Steven AKA SurreySnYder
SurreySnYder
SurreySnYder
Thanks,

again, this may make me look really stupid, i am using GLUT, and there does not seem to be any reference to a GL context, what line or lines should i expect to see in this programme?

Steven
SurreySnYder
SurreySnYder
SurreySnYder
This is the code i am using in the object, it uses the NEHE TGA loader, although i have used a number of other loaders.

#include "drawText.h"

int drawText::LoadGLTextures() // Load Bitmaps And Convert To Textures
{

int Status=FALSE; // Status Indicator

// Load The Bitmap, Check For Errors.
if (LoadTGA(&textures[0], "Text/WhiteONBlue/UpperA.tga"))
{
Status=TRUE; // Set The Status To TRUE
cout << "LOADED" << endl;
for (int loop=0; loop<1; loop++) // Loop Through Both Textures
{
// Typical Texture Generation Using Data From The TGA ( CHANGE )
glGenTextures(1, &textures[loop].texID); // Create The Texture ( CHANGE )
glBindTexture(GL_TEXTURE_2D, textures[loop].texID);
glTexImage2D(GL_TEXTURE_2D, 0, 3, textures[loop].width, textures[loop].height, 0, GL_RGBA, GL_UNSIGNED_BYTE, textures[loop].imageData);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

if (textures[loop].imageData) // If Texture Image Exists ( CHANGE )
{
free(textures[loop].imageData); // Free The Texture Image Memory ( CHANGE )
}
}
}

return Status; // Return The Status
}

drawText::drawText(){

LoadGLTextures();

}

drawText::~drawText(){

}

void drawText::drawTheText(string theText){
if(theText != ""){
for(int i = 0; i< theText.length();i++){
if(theText.substr(i,1) == "A")
drawUA();
if(theText.substr(i,1) == "B")
drawUB();
if(theText.substr(i,1) == "C")
drawUC();
}
}
}

void drawText::drawUA(){



glBindTexture ( GL_TEXTURE_2D, textures[0].texID);
//cout << glGetError() << endl;
glBegin ( GL_QUADS );
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.609375f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.609375f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 1.0f, 0.0f);
glEnd();
glTranslatef(0.609375f, 0.0f, 0.0f);




}

void drawText::drawUB(){



glBindTexture ( GL_TEXTURE_2D, textures[0].texID );
glBegin ( GL_QUADS );
glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.515625f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.515625f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 1.0f, 0.0f);
glEnd();
glTranslatef(0.515625f, 0.0f, 0.0f);



}

void drawText::drawUC(){



glBindTexture ( GL_TEXTURE_2D, textures[0].texID );
glBegin ( GL_QUADS );
glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.5625f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.5625f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 1.0f, 0.0f);
glEnd();
glTranslatef(0.5625f, 0.0f, 0.0f);



}



Kylotan
Kylotan
It does occur to me that you're not checking many return values. And did you call glEnable(GL_TEXTURE_2D) elsewhere as lubby mentioned?
SurreySnYder
SurreySnYder
Thanks for your help, i have solved the problem, the textures were being created in the constructor, and not after the glut window has been created, have solved this stupid problem now! only 3 days wasted!!!

thanks for your speedy help!

steven
SurreySnYder

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.