• 12
• 12
• 9
• 10
• 13

# Sprite class...

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

## Recommended Posts

Hello, i am trying to make a sprite class, that well hold a texture, and all the settings for it in the class, now i based this off lession06(the first texture lesson, it might not be 6) but it doesnt seem to work. it just draws a blank quad....and ideas as to why? here is the file, thank you File: www.mindcasterstudios.com/kc_0045/sprite_main.h Edit: Btw LoadBMP is in the "Txt_load.h" file, i copyed it exactly from the lession

##### Share on other sites
Just some general ideas:
-Did you eneble 2d texturing.
-Did you set color to white.
-Take a look at glTexImage2D specification as some of your parameters are a bit fishy.
most probably:
-You don't create all mipmaps. You should either create them by code (manual downsampling), use GLU, or use automatic mipmap generation via extension : glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE ); (I perfer this way; It's fast and it's supported on basicly anything from TNT up.)

And few style/design notes:
-TextureImage does not have to be class members. You are redefining it again in function.
-TextureImage should not be array. Just a simple pointer is enough.
-Do you have any reason for using int/TRUE/FALSE over boolean/true/false?

##### Share on other sites
ok thank you, i had it working once, but i tryed to change it and now its not working again :( iv been trying for a while but i still cant figure it out, i tryed making the function so more then one texture can be loaded, but it didnt seem to work, here is what i have

GLuint LoadTexture(char* Fl){    int Status=FALSE;    AUX_RGBImageRec* Timg;    GLuint txt;	memset(Timg,0,sizeof(void *)*1);	// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit	if (Timg=LoadBMP( Fl ))	{        Status=TRUE;				glGenTextures(1, &txt);		// Typical Texture Generation Using Data From The Bitmap		glBindTexture(GL_TEXTURE_2D, txt);		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, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, Timg->data);	}	if (Timg)	{		if (Timg->data)		{			free(Timg->data);		}		free(Timg);	}	return txt;}

and then i have a pointer(i think im not very good at using pointers and all that stuff) in the Csprites prviate
GLuint* texture;

then in the init i have

i did some error checking and it seems that the program crashes right after
*texture=LoadTexture(File_loc); , the LoadTexture function finishes fine, i just must not be calling it properly....any ideas? thanks in advanced

##### Share on other sites
> and then i have a pointer(i think im not very good at
> using pointers and all that stuff) in the Csprites prviate
> GLuint* texture;
> then in the init i have
> i did some error checking and it seems that the program crashes right after
> just must not be calling it properly....any ideas? thanks in advanced

If it is crashing right after this, it could be because you aren't using your pointers correctly.

The reason they use the pointer instead of a variable is because glGenTextures allows you to create more than one texture at a time. I personally have my code set up as follows.

GLuint texture=0;
glGenTextures(1, &texture); // Create The Texture
glBindTexture(GL_TEXTURE_2D, texture);

however, if you are committed to the whole pointer thing, you do need to allocate some ints for texture.

GLuint *texture=NULL;
texture = new GLuint[1];// or more if you want more textures
glGenTextures(1, texture); // Create The Texture
glBindTexture(GL_TEXTURE_2D, *texture);

Secondly, when you are drawing your quad, are you binding to the texture and passing the texture coordinates?