Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Texture problem in OpenGL

  1. #1

    Texture problem in OpenGL

    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
    [pascal]
    var texture: TGLBMP;
    [/pascal]

    this is in the Form1.create procedure
    [pascal]
    procedure Setup;
    begin
    t.texture:=TGLBMP.Create;
    t.texture.LoadImage('tex.bmp');
    t.texture.GenTexture(false,false);
    end;
    [/pascal]

    and this is in the render procedure
    [pascal]
    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;
    [/pascal]

    hm it can be a simple blackout but i dont find the problem?

    Thanks

  2. #2

    Texture problem in OpenGL

    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

  3. #3

    Texture problem in OpenGL

    thanks for reply

    the quad is missing :cry:
    ill try since 12pm without success

    here my initial code

    [pascal]
    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;
    [/pascal]

  4. #4

    Texture problem in OpenGL

    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

  5. #5

    Texture problem in OpenGL

    are you sure that the texture is power-of-two dimensions?
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  6. #6

    Texture problem in OpenGL

    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.

  7. #7

    Texture problem in OpenGL

    Daikrys, then try to post everything in your render procedure

    And do as Paulius suggested: glmatrixmode(gl_modelview);
    after gluperspective
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  8. #8

    Texture problem in OpenGL

    i localisated the problem but cant figure it

    when i create a opengl texture with Gentexture then i cant see everything

    [pascal]
    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;
    [/pascal]

    [pascal]
    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;
    [/pascal]

  9. #9

    Texture problem in OpenGL

    Do you remember to initialize ID in your texture record? before the if loop?
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  10. #10

    Texture problem in OpenGL

    i not sure what you mean?
    textureid is a TGLUInt

    i have upload my files
    http://<br /> http://daikrys.funpic...le=texture.zip(~85kb)

    please have a look

    Thanks

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Comodo SSL