using multiple textures
Hi,
I'm trying to display several quads with textures, but so far i'm not getting anywhere.
If I only use one texture, it displays perfectly.
But when I try to use more than one, the other textures show up as white. The bitmaps used are 128x128 pixels.
I'm using VS2005 sp1 and have tried tao 2.0 and the latest beta (2.1.0.12/1.0.0.4).
This is the code I use for loading the textures:
texture1 = new int[] { 0 };
//generate holders for 5 textures
Gl.glGenTextures(1, texture1);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture1[0]);
bitmap1 = new Bitmap("c:\\dv_ecg.bmp");
data1 = bitmap1.LockBits(new Rectangle(0, 0, bitmap1.Width, bitmap1.Height),
ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGB, data1.Width, data1.Height, 0,
Gl.GL_BGR, Gl.GL_UNSIGNED_BYTE, data1.Scan0);
bitmap1.UnlockBits(data1);
The code i use for rendering the textures:
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_NEAREST);// LINEAR);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_NEAREST);
Gl.glEnable(Gl.GL_TEXTURE_2D);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture1[0]);
Gl.glBegin(Gl.GL_QUADS);
// Display a quad texture to the screen
Gl.glColor3f(1f, 1f, 1f);
// Display the top left vertice
Gl.glTexCoord2f(0.0f, 0.0f);
Gl.glVertex3f(startX, startY, 0.0f);
// Display the bottom left vertice
Gl.glTexCoord2f(0.0f, 1.0f);
Gl.glVertex3f(startX, endY, 0.0f);
// Display the bottom right vertice
Gl.glTexCoord2f(1.0f, 1.0f);
Gl.glVertex3f(endX, endY, 0.0f);
// Display the top right vertice
Gl.glTexCoord2f(1.0f, 0.0f);
Gl.glVertex3f(endX, startY, 0.0f);
Gl.glEnd();
When using the above code for one texture, it's ok, when using multiple textures only the last one displays ok, the others remain white.
I've tried using a single array (textures[]) to store the textures, or a seperate array (texture1[], texture2[], etc). No luck... is there anyone who can help out?
Kind regards,
Sander

texture1 = new int[] { 0
texture1 = new int[] { 0 };//generate holders for 5 textures
Gl.glGenTextures(1, texture1);
generates 1 texture, did you try
texture1 = new int[5];//generate holders for 5 textures
Gl.glGenTextures(5, texture1);
and then load/render the textures using texture1[0] to texture1[4]?
I did, but it yields exactly
I did, but it yields exactly the same result.
I've tried the array approach, I've tried separate variables for bitmap en textures, everything I can think of. There must be something logically wrong with the way I set up and render the textures, I suppose...
Does anyone have a clue?
How are you rendering them?
How are you rendering them? All at once or one by one?
I repeat the code between
I repeat the code between "#region texture 1" and "#endregion" for each texture (using texture1[], texture2[] etc, or even texture1[0], texture1[1] etc), then end with Gl.glDisable(Gl.GL_TEXTURE_2D);.
I see no #regions but your
I see no #regions but your loop should start with the 2nd glBindTexture and end with glEnd. And you should do the same when loading ofcourse, starting with the 1st glBindTexture, ending with UnlockBits.
I suppose that's exactly
I suppose that's exactly what I do...
For completeness, here's my render code (and the missing regions)
#region texture 1
Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture1[0]);
Gl.glBegin(Gl.GL_QUADS);
Gl.glColor3f(1f, 1f, 1f);
// Display the top left vertice
Gl.glTexCoord2f(0.0f, 0.0f);
Gl.glVertex3f(startX, startY, 0.0f);
// Display the bottom left vertice
Gl.glTexCoord2f(0.0f, 1.0f);
Gl.glVertex3f(startX, endY, 0.0f);
// Display the bottom right vertice
Gl.glTexCoord2f(1.0f, 1.0f);
Gl.glVertex3f(endX, endY, 0.0f);
// Display the top right vertice
Gl.glTexCoord2f(1.0f, 0.0f);
Gl.glVertex3f(endX, startY, 0.0f);
Gl.glEnd();
#endregion
Ok, I found the
Ok,
I found the solution:
Before every Gl.glTexImage2D() call, the following call should be made
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_NEAREST);
If this call is missing, the textures show up as white.
Is this behavior explainable?
Regards,
Sander
If you change Gl.GL_NEAREST
If you change Gl.GL_NEAREST with Gl.GL_LINEAR, does it still work? What about Gl.GL_LINEAR_MIPMAP_NEAREST?
------
OpenTK
Hi StApostol, Thanks for
Hi StApostol,
Thanks for your reply.
I will be back @ work next tuesday, and I'll report on your questions then.
Regards,
Sander
I've tried the
I've tried the following:
GL_LINEAR - works like GL_NEAREST, but still need to issue this call before every glTexImage2D call
GL_LINEAR_MIPMAP_NEAREST - doesn't work, all textures show up as white
Regard,
Sander
GL_LINEAR - works like
GL_LINEAR - works like GL_NEAREST, but still need to issue this call before every glTexImage2D call
That's correct. You need to set texture parameters for each texture (at some point after glGenTextures).
GL_LINEAR_MIPMAP_NEAREST - doesn't work, all textures show up as white
This means you are not building mipmaps for the texture, i.e. you only upload a texture for level-0 (check the 'level' parameter in glTexImage2D).
------
OpenTK