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

Tuxtures handled within class

Started by Authustian Oct 16, 2001 at 4:26 PM 8 replies 1.8k views
Original Post
Authustian
Authustian
ok, i started of by tring to make a texture class, you know, pass in the file name in it''s constructor and there ya go, have all your texture stuff encapsulated so yo don''t mess with it. It didn''t work, all i got were white cubes, so i caved in and just added the functions normaly. now i try to make a cube class. I''m working on a game that uses alot of cubes, so i figured a class would be a good addition to the engine. Now i run into the same problem. i think it has something to do with textures being stored in the class, but i have no idea why it doesn''t work. I''m useing Nehe''s code (of course) for LoadGLTexture. here''s the code if you want to check it out.
  
class CCube
{

public:
	CCube(float fsize, char *Filename)
	{
		glEnable(GL_TEXTURE_2D);
		LoadGLTexture(texture, Filename);
		MySize = fsize;
		Location.x = 0.0f;
		Location.y = 0.0f;
		Location.z = 0.0f;
		SphereRad = (float)2*sqrt(MySize*MySize + MySize*MySize);		//calcultae spherical volume for fustrum culling

	};

	~CCube(){};

	void SetLoc(CVector newLoc)
	{
		Location.x = newLoc.x;
		Location.y = newLoc.y;
		Location.z = newLoc.z;
	};
	
	void SetLoc(float newx, float newy, float newz)
	{
		Location.x = newx;
		Location.y = newy;
		Location.z = newz;
	};

	void Draw()
	{	
		glBindTexture(GL_TEXTURE_2D, texture[0] );
		glBegin(GL_QUADS);
			// Front Face

			glTexCoord2f(0.0f, 0.0f); glVertex3f(Location.x + -MySize, Location.y +  -MySize, Location.z + MySize);
			glTexCoord2f(1.0f, 0.0f); glVertex3f(Location.x +  MySize, Location.y +  -MySize, Location.z + MySize);
			glTexCoord2f(1.0f, 1.0f); glVertex3f(Location.x +  MySize, Location.y +  MySize,  Location.z + MySize);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(Location.x + -MySize, Location.y +  MySize,  Location.z + MySize);
			// Back Face

			glTexCoord2f(1.0f, 0.0f); glVertex3f(Location.x + -MySize, Location.y + -MySize, Location.z + -MySize);
			glTexCoord2f(1.0f, 1.0f); glVertex3f(Location.x + -MySize, Location.y +  MySize, Location.z + -MySize);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(Location.x +  MySize, Location.y +  MySize, Location.z + -MySize);
			glTexCoord2f(0.0f, 0.0f); glVertex3f(Location.x +  MySize, Location.y + -MySize, Location.z + -MySize);
			// Top Face

			glTexCoord2f(0.0f, 1.0f); glVertex3f(Location.x + -MySize, Location.y +  MySize, Location.z + -MySize);
			glTexCoord2f(0.0f, 0.0f); glVertex3f(Location.x + -MySize, Location.y +  MySize, Location.z +  MySize);
			glTexCoord2f(1.0f, 0.0f); glVertex3f(Location.x +  MySize, Location.y +  MySize, Location.z +  MySize);
			glTexCoord2f(1.0f, 1.0f); glVertex3f(Location.x +  MySize, Location.y +  MySize, Location.z + -MySize);
			// Bottom Face

			glTexCoord2f(1.0f, 1.0f); glVertex3f(Location.x + -MySize, Location.y + -MySize, Location.z + -MySize);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(Location.x +  MySize, Location.y + -MySize, Location.z + -MySize);
			glTexCoord2f(0.0f, 0.0f); glVertex3f(Location.x +  MySize, Location.y + -MySize, Location.z +  MySize);
			glTexCoord2f(1.0f, 0.0f); glVertex3f(Location.x + -MySize, Location.y + -MySize, Location.z +  MySize);
			// Right face

			glTexCoord2f(1.0f, 0.0f); glVertex3f(Location.x +  MySize, Location.y + -MySize, Location.z + -MySize);
			glTexCoord2f(1.0f, 1.0f); glVertex3f(Location.x +  MySize, Location.y +  MySize, Location.z + -MySize);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(Location.x +  MySize, Location.y +  MySize, Location.z +  MySize);
			glTexCoord2f(0.0f, 0.0f); glVertex3f(Location.x +  MySize, Location.y + -MySize, Location.z +  MySize);
			// Left Face

			glTexCoord2f(0.0f, 0.0f); glVertex3f(Location.x +  -MySize, Location.y + -MySize, Location.z + -MySize);
			glTexCoord2f(1.0f, 0.0f); glVertex3f(Location.x +  -MySize, Location.y + -MySize, Location.z +  MySize);
			glTexCoord2f(1.0f, 1.0f); glVertex3f(Location.x +  -MySize, Location.y +  MySize, Location.z +  MySize);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(Location.x +  -MySize, Location.y +  MySize, Location.z + -MySize);
		glEnd();		// Done Drawing Quads

	};

private:
	GLuint	texture[1];
	float MySize;
	CVector Location;
	float SphereRad;

};
  
Thanx in advance for any help. ------------------------------------------------- Don''t take life too seriously, you''''ll never get out of it alive. -Bugs Bunny
-------------------------------------------------Don't take life too seriously, you''ll never get out of it alive. -Bugs Bunny
Authustian
Authustian
I realy want to know what i''m doing wrong. Anyone?

-------------------------------------------------
Don''t take life too seriously, you''''ll never get out of it alive. -Bugs Bunny
-------------------------------------------------Don't take life too seriously, you''ll never get out of it alive. -Bugs Bunny
dadio
dadio
your class seems ok.
I would check the LoadGLTexture(texture, Filename);
since you created texture[1], are you sure you sould send texture to your LoadGLTexture? maby send texture[0] or check to make sure the LoadGLTexture function returnes correctly.

since you only have one texture, don''t define an array. just a simple GLuint texture; will do.

Also make sure your texture is the correct size (power of 2).

And last thing, make sure your consructor is accessed at all...

enjoy, and good luck.
lunasol
lunasol
few weeks ago, i ran into a similar problem. Look at

http://www.gamedev.net/community/forums/topic.asp?topic_id=60592

hope that help

lunasol
Lukerd
Lukerd
I had the same problem. The textures wouldn''t load in the constructor they only load in the initGL function. Its very strange.


"To err is human, to really mess up requires a computer"
"To err is human, to really mess up requires a computer"
Authustian
Authustian
well, i made a CCube::LoadTex() function that runs all the same texture loading functions and everything, and i call it in the init function, and it all seems to work fine... i don''t get it but as long as it works i''m happy

-------------------------------------------------
Don''t take life too seriously, you''''ll never get out of it alive. -Bugs Bunny
-------------------------------------------------Don't take life too seriously, you''ll never get out of it alive. -Bugs Bunny
TheMummy
TheMummy
The Texture loading will never work when you try to load textures into gl before you have a running OpenGL context/window .... And you even get no glError codes ....
So befor initialize your classes ensure that your context has been initialized by your main module ..

Topic Locked

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

Sign in to reply to this topic.