texture object problems

Hey all,

I'm trying to use texture objects with the simpleopenglcontrol, however it's not displaying properly. It seems like the same problem when I have float vs int as params if that makes sense. Here's my code:

//Init Section of code starts here
textInt = new int[1];

// Generate 1 texture object ID
Gl.glGenTextures(1, textInt);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, textInt[0]);

// Set Texture mapping parameters
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_REPEAT);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_REPEAT);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);

Bitmap bitmap = new Bitmap("images/ftitle.bmp");
System.Drawing.Imaging.BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
titleWidth = data.Width;
titleHeight = data.Height;
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA, titleWidth, titleHeight, 0, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, data.Scan0);

bitmap.UnlockBits(data);
//Init Section of code ends here

//Drawing section of code starts here
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glPushMatrix();
Gl.glLoadIdentity();
Gl.glScaled(pz, pz, 1);
Gl.glTranslated(px, wnd_h / pz + py, 0);

//draw title area
Gl.glBindTexture(Gl.GL_TEXTURE_2D, textInt[0]);
Gl.glBegin(Gl.GL_QUADS);
Gl.glTexCoord2i(0, 0);
Gl.glVertex2i(0, 0);
Gl.glTexCoord2i(titleWidth, 0);
Gl.glVertex2i(titleWidth, 0);
Gl.glTexCoord2i(titleWidth, -titleHeight);
Gl.glVertex2i(titleWidth, -titleHeight);
Gl.glTexCoord2i(0, -titleHeight);
Gl.glVertex2i(0, -titleHeight);
Gl.glEnd();
//Drawing Section of code ends here

Any ideas? It is in the correct spot because when I change the pz value (zoom level) that box changes colors in some way, but not in a useful way to me Wink Tongue

Thanks,

Mike

First: "it's not displaying

First: "it's not displaying properly" isn't very helpful, what is supposed to show and what is what you actually get (is there texturing at all fe.)?

Second: A quick look at your code reveals that GDI bitmaps are in OpenGL BGRA format, not RGBA.

----------------------
Download Tao svn snapshot build
Experimental Tao rpms (OpenSUSE Build Service)

I saw that they were BRGA,

I saw that they were BRGA, however, I didn't see that as an option for GL_BRGA, I will look again.

Not displaying properly means that I have a title graphic, but when applying the texture to my quad, it shows as black under no scaling, white when zooming in (increase scaling) and some different brown/red color when zooming out (decrease scaling). Zooming in always keeps white, while zooming out makes it change colors depending on how zoomed out.

Also, are texture objects restricted to size power of 2, I read that the other method is, but documentation on the objects seems somewhat muddled on the net.

Thanks,

Mike

There is a GL_BGRA pixel

There is a GL_BGRA pixel format, which works perfectly with GDI+ textures (it's a little faster to load, too). If this doesn't fix the issue, can you upload a screenshot somewhere? Maybe it will help find out what's wrong.

The power-of-2 limit was lifted with GL2.0 or GL2.1, so if your video card is relatively new (as in, after 2003) it should support any texture dimensions with the standard functions (no extensions or anything).

------
OpenTK

I am going to try using the

I am going to try using the float version of the texture coords and go counterclockwise with both the texture and the polygon. I thought that the integer version of the texture coords was not bounded by [0..1], but it seems that maybe it is Wink Tongue

Mike

Ah ha! I forgot to enable

Ah ha!

I forgot to enable texture mapping Wink Tongue

But there is still a problem. I draw the texture onto the quad and it's sort of right, but there's a quad that is masking my scene as well... it kinda making all the other colors darker... Then as you zoom out, the mask changes colors and makes everything tinted yellow, gree, etc. But if you zoom in too far, it's finc, the graphc comes in just as expected, thought the mask stays Arf Hard to explain, lol

Mike

More info on this problem.

More info on this problem. The "mask" shows up even when commenting out the drawing texcoords2d. It doesn't go away until you comment out the genTexture stuff as well.

More info part 2. This

More info part 2. This block seems to be directly responsible, as when it's not there, no mask or texture (expected), but when it is there, the mask plagues the screen, even with out drawing the ploygon and using textcoord2df, etc

Bitmap bitmap = new Bitmap("images/ftitle.bmp");
System.Drawing.Imaging.BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
titleWidth = data.Width;
titleHeight = data.Height;
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA, titleWidth, titleHeight, 0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, data.Scan0);

bitmap.UnlockBits(data);

Thanks!

Mike

Theme by La Boite a site | Powered by Drupal