View Full Version : Texture problem in OpenGL
Daikrys
04-08-2005, 02:02 PM
hi there,
my problem is not a joke, i use the DGLOpenGL.pas for a short time
and when i try to load an texture with GLBMP i dont saw something :shock:
heres the simple code:
my texture
var texture: TGLBMP;
this is in the Form1.create procedure
procedure Setup;
begin
t.texture:=TGLBMP.Create;
t.texture.LoadImage('tex.bmp');
t.texture.GenTexture(false,false);
end;
and this is in the render procedure
t.texture.Bind;
glbegin(gl_quads);
glTexCoord2f(0.0, 0.0);
glvertex3f(-1,1,-2);
glTexCoord2f(1.0, 0.0);
glvertex3f(-1,0,-2);
glTexCoord2f(1.0, -1.0);
glvertex3f(0,0,-2);
glTexCoord2f(0.0, -1.0);
glvertex3f(0,1,-2);
glend;
hm it can be a simple blackout but i dont find the problem?
Thanks
Paulius
04-08-2005, 02:37 PM
So what do you get: quad without texture or no quad at all? If the quad is missing then the problem is elsewhere, if the texture is missing then you probably forgot to enable texturing
Daikrys
04-08-2005, 03:46 PM
thanks for reply :)
the quad is missing :cry:
ill try since 12pm without success :(
here my initial code
procedure TForm1.FormCreate(Sender: TObject);
var i: integer;
begin
InitOpenGL;
DC := GetDC(Handle);
RC := CreateRenderingContext(DC, [opDoubleBuffered], 32, 24, 0, 0, 0, 0);
ActivateRenderingContext(DC, RC);
SetupPixelFormat;
Setup;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
DeactivateRenderingContext;
wglDeleteContext(RC);
ReleaseDC(Handle, DC);
end;
procedure TForm1.FormResize(Sender: TObject);
begin
if HandleAllocated then
begin
glViewport(0, 0, ClientWidth, ClientHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
gluPerspective(45, ClientWidth/ClientHeight, 0.1, 1000);
end;
end;
procedure TForm1.SetupPixelFormat;
begin
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
end;
Paulius
04-08-2005, 04:05 PM
You?¢_~re problem has nothing to do with texturing then. In FormResize matrix mode is set to projection and never returned to model view, it?¢_Ts likely translate/rotate/scale are corrupting you?¢_Tre projection matrix
JSoftware
04-08-2005, 04:25 PM
are you sure that the texture is power-of-two dimensions?
Paulius
04-08-2005, 04:45 PM
If texture was invalid then OpenGL would act like no texturing was used, if he cant see his quad and no culling is used then theres a problem with it's transformation.
JSoftware
04-08-2005, 06:07 PM
Daikrys, then try to post everything in your render procedure
And do as Paulius suggested: glmatrixmode(gl_modelview);
after gluperspective
Daikrys
04-08-2005, 06:21 PM
i localisated the problem but cant figure it :(
when i create a opengl texture with Gentexture then i cant see everything
procedure TGLBMP.GenTexture();
begin
if Assigned(rgbBits) then begin
// If a texture object has already been created, delete it
if TextureID > 0 then
glDeleteTextures(1, TextureID);
// Create a new OpenGL texture object
glGenTextures(1, TextureID);
glBindTexture(GL_TEXTURE_2D, TextureID);
// Set up parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texWrapS);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texWrapT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
if (iFormat = RGB) then
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, PByte(rgbBits))
else
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, Width, Height, GL_BGRA, GL_UNSIGNED_BYTE, PByte(rgbBits))
end;
end;
procedure Render;
begin
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glLoadidentity;
gltranslatef(0,0,-6);
//textur.Bind;
glbegin(gl_quads);
glTexCoord2f(0.0, 0.0);
glvertex3f(-1,1,-2);
glTexCoord2f(1.0, 0.0);
glvertex3f(-1,0,-2);
glTexCoord2f(1.0, -1.0);
glvertex3f(0,0,-2);
glTexCoord2f(0.0, -1.0);
glvertex3f(0,1,-2);
glend;
SwapBuffers( DC);
end;
JSoftware
04-08-2005, 06:26 PM
Do you remember to initialize ID in your texture record? before the if loop?
Daikrys
04-08-2005, 06:53 PM
i not sure what you mean?
textureid is a TGLUInt
i have upload my files
http://daikrys.funpic.de/download.php?file=texture.zip(~85kb)
please have a look
Thanks :)
JSoftware
04-08-2005, 07:01 PM
hehe you have forgot to have a bitmap named tex.bmp in the folder :wink:
it works like a charm to me when i place a texture in the folder :P
Paulius
04-08-2005, 07:19 PM
So there?¢_Ts something about you?¢_Tre bitmap which make the texture totally black. Edit: That texture loader looks buggy, got the same result with 8bpp bitmap
JSoftware
04-08-2005, 07:21 PM
So there?¢_Ts something funky about you?¢_Tre bitmap which make the texture totally black
if there's a bitmap :wink:
Daikrys
04-08-2005, 07:42 PM
oh man youre right it work with jpg but not with my bmp and png's
oh really thanks i was to be in doubt about my brain :P
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.