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

Texturing Problem with OpenGL

Started by Richirich Mar 23, 2009 at 3:04 AM 4 replies 1.4k views
Original Post
Richirich
Richirich
Hello there! I'm pretty new to opengl but i used directX then I decided to use opengl. I'm having serious problems with the Textureing. My Problem is that i do not understand how GL works. 1) At first i call Gl.glGenTextures(Gl.GL_TEXTURE_2D, out i); (I use mono & tao). What does GL do in this call? Does it provide memory for a new Texture? 2)Secondly i call Gl.glBindTexture(Gl.GL_TEXTURE_2D, i);. I why do i Bind the Texture? is it nessessary to Bind Texture X just before i call the render statements? 3)After that i call Gl.glTexImage2D( Gl.GL_TEXTURE_2D, 0, Gl.GL_RGB5_A1, 64, 64, 0, Gl.GL_LUMINANCE, Gl.GL_UNSIGNED_SHORT, TexMulReader[id]); (The picture is an 64x64 graphic TexMulReader[id] gives back an byte[] with the data stored in it. 4) I call Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR); and Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR); 5) At the end i render my texture and before i call my render statements I call Gl.glBindTexture(Gl.GL_TEXTURE_2D, i); Now can you tell my what i'm doing wrong and how it works? Also can i also bind about 6000 textures with open gl about a time? thx Hurraa
Arkhyl
Arkhyl
Quote:
Original post by Richirich
1) At first i call Gl.glGenTextures(Gl.GL_TEXTURE_2D, out i); (I use mono & tao).
What does GL do in this call? Does it provide memory for a new Texture?

The first parameter of glGenTextures is the number of textures you want to generate, and the second parameter is an array where it will stock each textureId.
So in order to generate one texture you have to do :
int [] tex = new int[1];Gl.glGenTextures(1, tex);

Quote:

2)Secondly i call Gl.glBindTexture(Gl.GL_TEXTURE_2D, i);.
I why do i Bind the Texture? is it nessessary to Bind Texture X just before i call the render statements?

Yes you have to bind texture X before calling the render statements because openGL need to know wich texture to use.

The remain of your code seems right to me.
Quote:

Now can you tell my what i'm doing wrong and how it works? Also can i also bind about 6000 textures with open gl about a time?

Why do you whant to bind that much textures at the same time to begin with?
Richirich
Richirich
I don't know because it needs time to bind a texture, doesn't it? so if i bind it at loading time i have more time left to render...

Because i render a terrain with about 360 tiles (rect wit 44x44) and each tile can have different texture. If i have bound every texture i don't have to load it!

Also i didn't use an array for the glGenTexture(...)...

thx

Eraser85
Eraser85
what you can do is loading textures into vram at loading time (I guess you meant this by "if i bind it at loading time").

you can ask OpenGL to generate n names for n textures and store them in an array with just one call, as Arkhyl said. It's better than calling glGenTexture n times in a loop, i think.

lastly, I usually set texture parameters before calling glTexImage2D but that's not the rule, your way should work as well as mine..
V-man
V-man
Quote:
Original post by Richirich
I don't know because it needs time to bind a texture, doesn't it? so if i bind it at loading time i have more time left to render...

Because i render a terrain with about 360 tiles (rect wit 44x44) and each tile can have different texture. If i have bound every texture i don't have to load it!

Also i didn't use an array for the glGenTexture(...)...

thx


Do you really need to display 6000 textures at the same time on screen? That's way out of the "normal thing to do".
No, you can't bind 6000 textures.

You aren't forced to use an array for glGenTextures. I don't use an array either.
reoxthen
reoxthen
Quote:
Original post by Richirich
I don't know because it needs time to bind a texture, doesn't it? so if i bind it at loading time i have more time left to render...


this approach is not quite right. you neither have to load all your texture at the same time nor load them everytime you render. one of most important tasks of graphics engines is resource management. imho it has to decide which faces are visible and load textures to them (or a less smart algorithm with less computation time like deciding visible models instead of visible faces, etc.) and not unload them until they're not used anymore. since the user won't change the whole scene every frame it's not gonna be reloading everything every frame you render. and don't worry, you will still have the time to render anything you want.

Topic Locked

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

Sign in to reply to this topic.