Jump to content
  • Advertisement
Sign in to follow this  
Christen

OpenGL Texturing 2D surfaces

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

Hi! I'm a newbie here so please go easy on me. Anyway, I just browsed how to create 2d surfaces on OpenGL and now my problem is, I can't seem to put textures in these surfaces. Oh, and I've used the famous "2D in OpenGL code"
int DrawGLScene(GLvoid)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	glEnable2D();
	glBindTexture(GL_TEXTURE_2D, texture[0]);
	glBegin(GL_QUADS);
		glTexCoord2d(0, 0); glVertex2d(0, 0);
		glTexCoord2d(640, 0); glVertex2d(640,0);
		glTexCoord2d(640, 480); glVertex2d(640, 480);
		glTexCoord2d(0, 480); glVertex2d(0, 480);
	glEnd();
	glDisable2D();

	return TRUE;
}

Share this post


Link to post
Share on other sites
Advertisement
A few common mistakes:
  • Is your texture power-of-two sized (e.g. 256 by 64)?

  • Do you have a valid OpenGL context when you create the texture


Also, texture coordinates should be in the range [0..1] if you don't want your texture to tile.

Enigma

Share this post


Link to post
Share on other sites
Quote:
Original post by PnP Bios
glEnable2D is not a valid function.

but i think he has defined the function himself (someone wrote some 2d enabling code that used a function with that name some time ago)

Share this post


Link to post
Share on other sites
OK, I've solved the problem by changing the texcoords, and resizing my image to 512x512.

Anyway, is there any method to display textures without sticking to that size limitation?

Share this post


Link to post
Share on other sites
You can get around the power-of-two restrication by:
  • Using gluBuild2DMipmaps to resize your image for you

  • Resizing your image to the nearest power of 2

  • Padding your image to the nearest power of 2 and changing the texture coordinates to only reference the portion of the texture that contains your image (tiling is not longer possible in this case)

  • Using a texture rectangle extention (i.e. GL_ARB_texture_rectangle). Texture coordinates then must be changed to lie in [0..dimension] to reference the full texture instead of [0..1]

  • Using an NPOT extention (i.e. GL_ARB_texture_non_power_of_two). Texture coordinates remain normalised as [0..1] in this case

  • Using OpenGL 2.0 - requires drivers that at time of writing have not been publicly released for most (any?) graphics cards


Enigma

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!