|
Draw texture in AllegroGL |
James Stanley
Member #7,275
May 2006
|
I have recently (just today...) decided that it is time for me to learn OpenGL/AllegroGL. I have managed to draw a square on the screen, but I am unable to texture that square. I have the following code:
Anybody know what's wrong with that? EDIT: |
Archon
Member #4,195
January 2004
|
bitmap = load_bitmap("images/gui/button.tga", NULL); gl_image = allegro_gl_make_texture_ex(AGL_TEXTURE_MASKED, bitmap, GL_RGBA); //Don't need anymore destroy_bitmap(bitmap); //ADD //Generate and bind a texture //glGenTextures(1, &gl_image); DELETE glBindTexture(GL_TEXTURE_2D, gl_image);
|
James Stanley
Member #7,275
May 2006
|
Still just a white rectangle. |
Archon
Member #4,195
January 2004
|
Can you check the return value of the load_bitmap call? [edit] glTexCoord2f(0, 0); glVertex3f(-0.5, -0.5, 0); glTexCoord2f(1, 0); glVertex3f(0.5, -0.5, 0); glTexCoord2f(1, 1); glVertex3f(0.5, 0.5, 0); glTexCoord2f(0, 1); glVertex3f(-0.5, 0.5, 0);
|
James Stanley
Member #7,275
May 2006
|
load_bitmap() returns a bitmap, and the current order is the same as yours. |
Archon
Member #4,195
January 2004
|
OK. What does allegro_gl_make_texture_ex return? It should be above 0. |
gnolam
Member #2,030
March 2002
|
Quote: glGenTextures(1, &gl_image); Remove that. -- |
James Stanley
Member #7,275
May 2006
|
Aha! What could be causing it to be 0, then? Bad options? |
GullRaDriel
Member #3,861
September 2003
|
File not found, Not a bmp file, wrong filename. shouldn't it be "my_dir\\myname.bmp" "Code is like shit - it only smells if it is not yours" |
James Stanley
Member #7,275
May 2006
|
Aha! The problem is that I had forgot to use a power-of-2 image! Quote: shouldn't it be "my_dir\\myname.bmp" No... |
Archon
Member #4,195
January 2004
|
Quote: Aha! The problem is that I had forgot to use a power-of-2 image! I wasn't sure if AllegroGL did something about that or not but it would've been my next question. Quote: shouldn't it be "my_dir\\myname.bmp" Using forward slashes are perfectly fine (and recommended) with Windows. I don't think that using blackslashes work in Unix though. |
GullRaDriel
Member #3,861
September 2003
|
AllegroGL handles non power of two texture, even if the gfx card does not support it. "Code is like shit - it only smells if it is not yours" |
James Stanley
Member #7,275
May 2006
|
So why did it suddenly start working when I put it as a power of two? Also, is there a way to get mouse co-ordinates in OpenGL? Or would I have to convert Allegro co-ordinates? |
Jakub Wasilewski
Member #3,653
June 2003
|
AllegroGL only allows npo2 textures on unsupporting hardware if you pass AGL_TEXTURE_RESCALE. This causes AGL to rescale the texture itself to fit the nearest power-of-2 size. Quote: Also, is there a way to get mouse co-ordinates in OpenGL? Or would I have to convert Allegro co-ordinates? The latter. One of the ways to do that is gluUnProject from GLUT. --------------------------- |
Archon
Member #4,195
January 2004
|
Quote: So why did it suddenly start working when I put it as a power of two? Probably because the way textures work in 3D graphical interfaces since the type used are float. Floating point numbers, with their dimensions in the powers of 2, fit 'nicely' in binary. Quote: Also, is there a way to get mouse co-ordinates in OpenGL? Or would I have to convert Allegro co-ordinates? Are you talking about the coordinates respective to the screen or coordinates to measure with what 3D objects you are "pointing at"? |
X-G
Member #856
December 2000
|
Er, it's mostly because you can assume a whole bunch of things if you do, not really because of floats. -- |
James Stanley
Member #7,275
May 2006
|
Jakub: I see. I'll use AGL_TEXTURE_RESCALE then. Thanks. Archon: I'm not doing 3D just yet, it's actual co-ordinate on the screen that I'm after. I've done it by converting allegro's co-ordinates now. EDIT: EDIT2: |
Archon
Member #4,195
January 2004
|
Quote:
I know I'm getting a bit off topic on my own thread, but how would I use the mask colour of a BITMAP to set the alpha channel of a texture? Also, look into: glAlphaTest glAlphaFunc
|
|