Jump to content
  • Advertisement
Sign in to follow this  
Stormtrooper

OpenGL Image not drawing

This topic is 3850 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

For some reason...my image isn't drawing. I know the image exists because I can write the values to the log(sizes return the right size, the texture handle returns the number 2), and the program isn't crashing when I try to draw the image. Its hard because the loading code is spread all over the place, but I doubt its the loading code.
	void Graphics::drawImage( boost::shared_ptr<gcn::OpenGLImage> texture, Utilities::Rect& src, Utilities::Coord &dest, Utilities::Color& color )
	{
		assert( texture );

		if( m_begansprites == false )
		{
			glEnable( GL_TEXTURE_2D );
			glBegin( GL_QUADS );
			m_begansprites = true;
		}

		// Draw the texture at it's default size if
		// a size is not defined
		if( src.width == 0 )
			src.width = texture->getWidth();

		if( src.height == 0 )
			src.height = texture->getHeight();
		
		float texX1	= src.x / (float)texture->getWidth();
		float texY1 = src.y / (float)texture->getHeight();
		float texX2 = (src.x + src.width) / (float)texture->getWidth();
		float texY2 = (src.y + src.height) / (float)texture->getHeight();

		glBindTexture( GL_TEXTURE_2D, texture->getTextureHandle() );

		glColor4ub( color.r, color.g, color.b, color.a );
		
		glTexCoord2f( texX1, texY1 );
		glVertex2f( dest.x, dest.y );

		glTexCoord2f( texX2, texY1 );
		glVertex2f( dest.x + src.width, dest.y );

		glTexCoord2f( texX2, texY2 );
		glVertex2f( dest.x + src.width, dest.y + src.height );

		glTexCoord2f( texX1, texY2 );
		glVertex2f( dest.x, dest.y + src.height );

		if( m_begansprites == true )
		{
			glEnd();
			glDisable( GL_TEXTURE_2D );
			m_begansprites = false;
		}
	}

Share this post


Link to post
Share on other sites
Advertisement
theres certain things u cant do between glBegin()..End()
one of them is binding a texture like youre doing there

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!