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

GL.BindTexture Borks

Started by Retro_Alt Jul 29, 2010 at 4:09 PM 3 replies 1.5k views
Original Post
Retro_Alt
Retro_Alt
Hi, I am having a rather strange problem, and I am hoping someone here might have some insights (or have had this problem in the past).

My issue is that when in the default texture name (0) GL.TexImage2D works perfectly, but if I try to create the texture with any other name (using GL.BindTexture) the texture is created but with nonsense data in it.

This code works perfectly, and I can see the texture in gDEbugger:
GL.BindTexture(TextureTarget.Texture2D, 0);GL.TexParameter(	TextureTarget.Texture2D, 	TextureParameterName.TextureMinFilter, 	(int)TextureMinFilter.Linear);GL.TexParameter(	TextureTarget.Texture2D, 	TextureParameterName.TextureMagFilter, 	(int)TextureMagFilter.Linear);GL.TexImage2D<byte>(	TextureTarget.Texture2D, 	0, 	PixelInternalFormat.R8, 	(int)width, 	(int)height, 	0, 	PixelFormat.Red, 	PixelType.UnsignedByte, 	data);


This code results in a texture that is the correct dimensions and same format, but with repetitive nonsense data in it:
GL.BindTexture(TextureTarget.Texture2D, 5);GL.TexParameter(	TextureTarget.Texture2D, 	TextureParameterName.TextureMinFilter, 	(int)TextureMinFilter.Linear);GL.TexParameter(	TextureTarget.Texture2D, 	TextureParameterName.TextureMagFilter, 	(int)TextureMagFilter.Linear);GL.TexImage2D<byte>(	TextureTarget.Texture2D, 	0, 	PixelInternalFormat.R8, 	(int)width, 	(int)height, 	0, 	PixelFormat.Red, 	PixelType.UnsignedByte, 	data);


Note that it doesn't matter if the id given to BindTexture is generated using GenTexture or if I just use a random number (like 5 in this example). I am certain this is running in a valid (and existent) GL context. Since this is GL 3.2 code, I do not call GL.Enable(GL_TEXTURE2D); (this just results with an INVALID_ENUM error).

I have scoured this forum and of course googled it, but couldn't find anyone else having this problem.

EDIT: One other thing I should mention is that I can switch the texture unit just fine (using GL.ActiveTexture), but it is still corrupt if the texture id is nonzero.

[Edited by - Retro_Alt on July 29, 2010 5:20:14 PM]
Thanks!Greg
KumGame07
KumGame07
How will you confirm that the texture ID "5" is not used for any other purpose (say a program ID or shader ID). The best way is to ask GL itself to give you an unused ID (using glGenTextures()). If you hate it for some reason (;)), just try with some higher value of ID (say 1000)
Best Regards,KumGame07
21st Century Moose
21st Century Moose
Quote:
Original post by KumGame07
How will you confirm that the texture ID "5" is not used for any other purpose (say a program ID or shader ID). The best way is to ask GL itself to give you an unused ID (using glGenTextures()). If you hate it for some reason (;)), just try with some higher value of ID (say 1000)


Quote:
Note that it doesn't matter if the id given to BindTexture is generated using GenTexture or if I just use a random number (like 5 in this example).


;)
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
V-man
V-man
Also, you should use texture ID starting from 1.
GL should have been designed to consider 0 as an invalid.
Also, with GL 3.0 forward compatible context and I think also for GL ES, you must use glGenTextures.
Retro_Alt
Retro_Alt
Argh, gDEBugger was lying to me. :(

Okay, so in a forward 3.2 context, gDEBugger shows corrupted textures, but in reality they are just fine and are rendered correctly.

So my code works :). gDEBugger less so...

Thanks!Greg

Topic Locked

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

Sign in to reply to this topic.