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

render textures

Started by highendman Feb 6, 2010 at 7:14 AM 7 replies 1.3k views
Original Post
highendman
highendman
Hello, I have a class "renderer" that renders all my sprites: It has a std::vector that stores pointers to all textures. You can add a texture with renderer::addTexture(Texture*). In the main loop you call renderer::draw(). But it doesn't work well (actually it doesn't work at all :D).

void Renderer::draw()
{
	for(int i=0; i<gfxList.size(); i++)
	{
		glBindTexture(GL_TEXTURE_2D, gfxList->getData());

    	glBegin( GL_QUADS );
	    	glTexCoord2f(0.0f, 0.0f); glVertex3f(0, 0, 1);    //yes the coordinates are static, but it's just for the moment 
	    	glTexCoord2f(1.0f, 0.0f); glVertex3f(1, 0,  1 );
	    	glTexCoord2f(1.0f, 1.0f); glVertex3f(1, 1, 1 );
	    	glTexCoord2f(0.0f, 1.0f); glVertex3f(0, 1, 1 );
   	 glEnd();
	}
}
Texture::getData() returns the GLuint.

Renderer gameGraphics;

Texture tex;

gameGraphics.addTexture(&tex);

...

gameGraphics.draw();
If I run this code, only the quad is displayed, but the actual texture is missing. I guess everyone is facepalming right now :D Thanks.
highendman
highendman
GL_TEXTURE_2D is enabled.

Texture.h
class Textur{	public:											Textur();										   ~Textur();	private:		ILuint								ILimgData;		GLuint								GLimgData;		std::string							imgPath;	public:		GLuint								getData();		std::string						    getPath();		bool								open(std::string nPath);};



Texture.cpp
Textur::Textur(){	imgPath = "pic.jpg";}Textur::~Textur(){}GLuint Textur::getData(){	return GLimgData;}string Textur::getPath(){	return imgPath;}bool Textur::open(string nPath){	imgPath = nPath;	ilGenImages(1,&ILimgData);				ilBindImage(ILimgData);				if (!ilLoadImage(nPath.c_str()))	{		PRINT("ERROR: Textur kann nicht geladen werden");		ilDeleteImages(1,&ILimgData);			return false;	}			long w, h, bpp, format;	unsigned char *texdata = NULL;	w       =ilGetInteger(IL_IMAGE_WIDTH);		h       =ilGetInteger(IL_IMAGE_HEIGHT);		bpp     =ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL); 	format  =ilGetInteger(IL_IMAGE_FORMAT);		texdata	=ilGetData();	glGenTextures(1,&GLimgData);			glBindTexture(GL_TEXTURE_2D, GLimgData);		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);  	gluBuild2DMipmaps(GL_TEXTURE_2D, bpp, w, h, format, GL_UNSIGNED_BYTE, texdata); 	return true;	}


I copied some parts out of different tutorials, so the code might be a bit confusing.
Jason Petrasko
Jason Petrasko
The examples I've seen use a call "ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);" to convert the images bytes after being loaded. Not sure if you need that or not.
highendman
highendman
what I forgot to say:
If I display textures "without" the Renderer-Class it works.

main.cpp
Texture tex;...while(isRunning){   ...   glBindTexture(GL_TEXTURE_2D, tex.getData());    glBegin( GL_QUADS );	glTexCoord2f(0.0f, 0.0f); glVertex3f(0, 0, 1);	glTexCoord2f(1.0f, 0.0f); glVertex3f(1, 0,  1 );	glTexCoord2f(1.0f, 1.0f); glVertex3f(1, 1, 1 );	glTexCoord2f(0.0f, 1.0f); glVertex3f(0, 1, 1 );    glEnd();   ...}
Jason Petrasko
Jason Petrasko
Well you have got me beat now. I'd have to be able to play and compile the whole project to see what is going on. You welcome to PM me if you want me to try and help that way.
AMike
AMike
Do you have some kind of face culling enabled in your renderer drawing code? This could prevent displaying the correct face of the quad.
mrchrismnh
mrchrismnh
Write the output of gfxList->getData() to a file every iteration. It may not be doing what you think it is.
"It's like naming him Asskicker Monstertrucktits O'Ninja" -Khaiy

Topic Locked

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

Sign in to reply to this topic.