Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » openGL texture filters and the mystery of the clueless programmer

This thread is locked; no one can reply to it. rss feed Print
openGL texture filters and the mystery of the clueless programmer
Albin Engström
Member #8,110
December 2006
avatar

So i'm following NeHe's tutorials on openGL i've reached texture filters and simple lightning (lesson 7) and not very surprisingly stumbled upon a problem (even if i'm the problem, whatever), in the tutorial he uses glaux to load his bitmaps, i use allegro and not necessarily the problem, it's probably related, anyway, here's the code i think is wrong(i don't think, i guess, because i don't have any facts):

glBindTexture(GL_TEXTURE_2D, tex[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, test01);

Note that i have no real knowledge of what these functions do, but i guess i'm just stating the obvious :).

tex = GLuint
test01 = allegro bitmap

My second guess is that the initialization code sucks, i'm attaching a picture which should prove more of a clue than anything else. i think... thanks!!

edit: btw, i forgot to do a thing before i took a picture of the "working" version, if anyone wonders why it looks so retared..

Archon
Member #4,195
January 2004
avatar

If you're using AllegroGL, use the normal BITMAP loading function, then use AllegroGL's allegro_gl_make_bitmap functions with that BITMAP.

Quote:

glBindTexture(GL_TEXTURE_2D, tex[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, test01);
Note that i have no real knowledge of what these functions do, but i guess i'm just stating the obvious :).

glBindTexture says "use/set this texture".

glTexParameter says "set some parameters for this texture (one that is currently glBindTexture-ed)". You're just setting the magnification/minification to linear which is blending the pixels on the screen when the texture on the screen is smaller or larger than the texture in memory. The other option is GL_NEAREST which just gets the nearest texel (texture pixel) and draws that pixel rather than blending it.

glTexImage2D says "set the texture's pixels". You supply the dimensions, whether it's RGB, BGR, RGBA etc, the data type etc...

Albin Engström
Member #8,110
December 2006
avatar

thank you :D. allegro_gl_make_bitmap doesn't seem to exist so i guessed you meant allegro_gl_make_texture, also, should i use the allegro_gl functions instead when creating a texture, they felt limited compared to the ones i mentioned in my main post but i don't think i need anything else. thanks for the description but i still can't get those functions to work, just in case i'd want to use them it could be good to know how.

Archon
Member #4,195
January 2004
avatar

Quote:

allegro_gl_make_bitmap doesn't seem to exist so i guessed you meant allegro_gl_make_texture

My mistake - it was an oversight (I don't use AllegroGL anyways).

Quote:

should i use the allegro_gl functions instead when creating a texture, they felt limited compared to the ones i mentioned in my main post

allegro_gl_make_texture creates a texture from a bitmap that is loaded into the allegro library.

You should be able to use the other image libraries for Allegro and then allegro_gl_make_texture on those.

However, you can change the values of the glTexParameter-s after you bind the texture even after the texture has been loaded... So you could do something like:

int myTexture = allegro_gl_make_texture(myBitmap,...);
destroy_bitmap(myBitmap);

glBindTexture(GL_TEXTURE_2D, myTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glTexParameter/glTex***** affect what texture is currently glBindTextured-ed.

Milan Mimica
Member #3,877
September 2003
avatar

Use allegro_gl_make_texture_ex(), since the non-ex version is deprecated. And there are so many things to care about when uploading the bitmap to the texture that you should let AGL do it. It is not just a few lines of code.

Albin Engström
Member #8,110
December 2006
avatar

Archon said:

glTexParameter/glTex***** affect what texture is currently glBindTextured-ed.

sweet, thanks! wait.. don't you mean "affect the currently glBindTextured-ed texture" or am i getting it wrong?

Archon said:

Use allegro_gl_make_texture_ex(), since the non-ex version is deprecated. And there are so many things to care about when uploading the bitmap to the texture that you should let AGL do it. It is not just a few lines of code.

:).

Archon
Member #4,195
January 2004
avatar

Quote:

wait.. don't you mean "affect the currently glBindTextured-ed texture" or am i getting it wrong?

It's the same meaning but worded differently.

Also, I didn't say that last quote ;)

Take note of that GL_TEXTURE_2D that is the first parameter for all of those functions. It is because you can use 1D and 3D textures as well (but not at the same time AFAIK). If you want to use multiple textures on the same polygon (eg. a character who is bleeding or is covered in slime) then you'll need to use the Multi-texture extensions.

Go to: