Sign in to follow this  

rendering textures in oop structure - HELP!!

This topic is 4728 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
If you are sure that the code is right, i would check that you have created the GL context before creating textures. Offhand this is a probable cause. Otherwise post some code for us to look at.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Its a different story with glut, as long as you are loading after glutInit (edit: and set the callbacks) you should be fine. I recommend that you post some code. Other thing you could be missing - glEnable(GL_TEXTURE_2D);

Share this post


Link to post
Share on other sites
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);



}



Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 4728 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this