Jump to content
  • Advertisement
Sign in to follow this  
Jeffi

Textures

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

Hey, how do I load and use more than one texture at once? The loading i think I know, but how do I tell OpenGL which Texture it's suposed to use on which Polygon? recall glBind or what? THX....

Share this post


Link to post
Share on other sites
Advertisement
Now I got a little bit more time to explain my problem(and push the topic back up*g*)

I'm trying to use more than one texture in my OpenGL Scene. I have an TextureLoading funktion, which looks like this:

<code>
public void LoadTexture(string filename)
{
Bitmap image = new Bitmap("tex\\" + filename + ".bmp");
image.RotateFlip(RotateFlipType.RotateNoneFlipY);
System.Drawing.Imaging.BitmapData bitmapdata;
Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);

bitmapdata = image.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly,
System.Drawing.Imaging.PixelFormat.Format24bppRgb);

GL.glGenTextures(texcount, texture);
GL.glBindTexture(GL.GL_TEXTURE_2D, texture[texcount]);
GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB8, image.Width, image.Height,
0, GL.GL_BGR_EXT, GL.GL_UNSIGNED_BYTE, bitmapdata.Scan0);
GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); // Linear Filtering
GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); // Linear Filtering

texcount++;
image.UnlockBits(bitmapdata);
image.Dispose();
}</code>

I tried to render 2 Polygons, one with texture[0] and one with texture[1] so I called the function (GL.)glBindTexture(GL.GL_TEXTURE_2D, texture[0]); rendered the first Polygon and than called GL.glBindTexture(GL.GL_TEXTURE_2D, texture[1]); and rendered the second Polygon... the Problem is OpenGL only renders the textures I loaded at last!?!?!?! And that's my problem... I can only use one texture or I've got to reload everytexture everytime I use them what is a performancekiller!


Hope somebody can help me...

Greets...

Share this post


Link to post
Share on other sites
To select another texture than the last one created simply write:

glBindTexture(GL_TEXTURE_2D, texture[the number of the texture you want to use]);

You are writing GL. before the function. i dont know hwy you are doing that butif it's neccecary to do for any reason you should do it here to:

GL.glBindTexture(GL.GL_TEXTURE_2D, texture[the number of the texture you want to use]);

Share this post


Link to post
Share on other sites
its because of this call

glGenTextures(texcount, texture);

this function requests a certain number of texture ID's and stores them in the pointer passed. For each texture you load you should be useing something like

glGenTextures(1, &texture[texcount]);

So you request 1 ID and store it in the apropriate array spot. Then use the bind to select which texture your useing.

Also whats with the "GL." everywhere?

Share this post


Link to post
Share on other sites
Every time you call your LoadTexture function, you overwrite your texture names with glGenTextures().

The first call works because you only generate one texture. The next call generates two textures (because of texcount++;) and overwrites the name of the texture you created in the first call because you use the same variable to store them in.

glGenTextures should only be called once, with the number of textures you want:

glGenTextures(num_of_tex_you_need, array_of_tex_names);

To generate one at a time:

glGenTextures(1, &address_of_a_tex_name);

Edit: I'm just too Slow, oh well.

Quote:
Original post by kaysik
Also whats with the "GL." everywhere?


I think he's using Java.

Share this post


Link to post
Share on other sites
No, no Java, but C# and the GL is the Class or Namespace they wrapped the OpenGL in... CSGL or something...

So if I unterstood all of you right, the Loading of the Textures should look like this:

someinitfunc()
{
GL.glGenTextures(numberoftexiwanttoloadatall(2), texture);
LoadTexture("texone");
LoadTexture("textwo");

}

public void LoadTexture(string filename)
{
Bitmap image = new Bitmap("tex\\" + filename + ".bmp");
image.RotateFlip(RotateFlipType.RotateNoneFlipY);
System.Drawing.Imaging.BitmapData bitmapdata;
Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);

bitmapdata = image.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly,
System.Drawing.Imaging.PixelFormat.Format24bppRgb);

//GL.glGenTextures(texcount, texture);
GL.glBindTexture(GL.GL_TEXTURE_2D, texture[texcount]);
GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB8, image.Width, image.Height,
0, GL.GL_BGR_EXT, GL.GL_UNSIGNED_BYTE, bitmapdata.Scan0);
GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); // Linear Filtering
GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); // Linear Filtering

texcount++;
image.UnlockBits(bitmapdata);
image.Dispose();
}

renderscene()
{
GL.glBindTexture(gl_tex_2d,tex[0]);
glBegin(firstPoly);
glEnd();
GL.glBindTexture(gl_tex_2d,tex[1]);
glBegin(secondPoly);
glEnd();
}


Got it right? I'll try it....


thx a lot

Share this post


Link to post
Share on other sites
k, works...

But now you've got to explain a few things to me...

The projekt I got right now, I only need a few(less than 5) texes but if I think about coding a game, I would need a lot more... so what is the way you do that? By Loading the game you create all texes and store them in ONE single array? Save the index and then call it back? Or do you split the texes up into different arrays or is that at all posible?

And the loading process:

glBindTex tells OpenGL what the active tex(pointer) is right? And then glTexImage2D "converts" the image into the OpenGL Texture, right? And glTexParameteri then adds some parameters, right?

Share this post


Link to post
Share on other sites
Quote:
Original post by Jeffi
k, works...

But now you've got to explain a few things to me...

The projekt I got right now, I only need a few(less than 5) texes but if I think about coding a game, I would need a lot more... so what is the way you do that? By Loading the game you create all texes and store them in ONE single array? Save the index and then call it back? Or do you split the texes up into different arrays or is that at all posible?


That's exactly right. Obviously it's impractical to have all your resources loaded all the time so you'd just load the batch that you need for the current scene.

Quote:
Original post by Jeffi
And the loading process:

glBindTex tells OpenGL what the active tex(pointer) is right? And then glTexImage2D "converts" the image into the OpenGL Texture, right? And glTexParameteri then adds some parameters, right?


Right again.

Share this post


Link to post
Share on other sites
Got another question:

How do I make a certain color in a Texture transparent? I once tried the function MakeTransparent(Color) out of the Bitmap Class of C# but than OpenGL didn't rendered the Texture at all...

Greets...

Got it...

thx alot for you help.....

[Edited by - Jeffi on October 22, 2004 5:19:08 PM]

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!