Advertisement

Texture loading in OpenGL

Started by March 06, 2002 04:32 PM
0 comments, last by Phobeus 22 years, 11 months ago
Hi guys, sorry, maybe this is really a newbish question, but... I am working with delphi and currently having a small problem with texture. My idea was to create a class and storage the texture in this class. Everything is working more than fine, since I am using two textures in a scene. First the loading of the texture seems 100 fine! If I am using something like glass.SetTexture; crate.SetTexture; he draws the crate texture pefectly and if I swap both texture the glass texture is shown fine, so he founds both textures! But if I am renering a cube with the first texture and then a cube with the second texture, the first cube has no texture at all, during the second is fine. If i draw both cube with one texture everything is fine again! So I am guessing that my "Settexture" is somehow earasing the first texture... or i am setting it wrong. So... here it is: glBindTexture(GL_TEXTURE_2D,texture); texture is in this case definited like: texture : GLuint; And in each class there''s another texture stored... so I am not sure what''s going wrong here... however my loading procedure also! PROCEDURE TDarkTexture.LoadTexture(name:pChar); VAR texture1: PTAUX_RGBImageRec; BEGIN; // Load Texture an OpenGL Texture texture1 := auxDIBImageLoadA(name); IF (NOT Assigned(texture1)) THEN HALT; // Create Texture glGenTextures(1, texture); glBindTexture(GL_TEXTURE_2D, texture); glTexImage2D(GL_TEXTURE_2D, 0, 3, texture1^.sizeX, texture1^.sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texture1^.data); END; hope you can still understand the opengl source, even if it''s delphi. i am currently not sure, what''s moving wrong, but i am 100% sure it must be the bind to the cube that''s wrong... because i made several test and the loading seems 100% fine. ThanXs for ANY idea Sincerly, Phobeus
Please visit http://dgl.thechaoscompany.net - A german site for delphi opengl programmers!
I know virtually nothing about delphi, but I think the problem might be:

  glGenTextures(1, texture);glBindTexture(GL_TEXTURE_2D, texture);  


glGenTextures takes a pointer to the unsigned intiger, when glBindTexture just needs the value. The problem might be that it is storing the texture in a area of memory you don''t own, and then when you try to switch textures, you can''t find the old one because texture wasn''t set to the right id. I don''t know how to fix it in delphi, but in C++ I would have wrote:

  glGenTextures(1, &texture);  


I hope that fixes it.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.

This topic is closed to new replies.

Advertisement