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

Thread: OpenGL: Silly texturing problem

  1. #1

    OpenGL: Silly texturing problem

    After a few years (maybe 5 or 6) I decided to pick up again on OpenGL programming and I ran into a strange problem.

    I load 6 textures using the glBitmap.LoadTexture function and I try to render a cube with different texture on each side.

    I enable texturing, bind the right texture, set normals, texture coordinates and vertices and I get the last texture I loaded on each side.

    What could be wrong? I've done this million times and I even digged up some old code that works and I'm doing exactly the same as in there... ops:
    If you develop an idiot proof system, the nature develops better idiots.

  2. #2

    OpenGL: Silly texturing problem

    Are you sure you are using glBindTexture for all sides seperately?

    In any case, some sample code would help..

  3. #3

    OpenGL: Silly texturing problem

    Here's the code:
    [pascal]
    procedure TSkyBox.Render;
    var
    i, j: Integer;
    begin
    glEnable(GL_TEXTURE_2D);
    glColor3f(1, 1, 1);
    glBegin(GL_QUADS);
    for i := 0 to 5 do
    begin
    glBindTexture(GL_TEXTURE_2D, TexID[i]);
    glNormal3fv(@Normals[i]);
    for j := 0 to 3 do
    begin
    glTexCoord2fv(@TexCoord[j]);
    glVertex3fv(@Vertices[Quads[i, j]]);
    end;
    end;
    glEnd; // GL_QUADS
    glDisable(GL_TEXTURE_2D);
    end;
    [/pascal]

    I had the texture ids written to a log file and they were 1-6, just like they should be with them being the only textures generated so far.
    For some reason the binding doesn't work.
    If you develop an idiot proof system, the nature develops better idiots.

  4. #4

    OpenGL: Silly texturing problem

    Figured it out, I have to bind the texture outside glBegin() - glEnd() blocks.

    [pascal]
    procedure TSkyBox.Render;
    var
    i, j: Integer;
    begin
    glColor3f(1, 1, 1);
    glEnable(GL_TEXTURE_2D);
    for i := 0 to 5 do
    begin
    glBindTexture(GL_TEXTURE_2D, TexID[i]);
    glBegin(GL_QUADS);
    glNormal3fv(@Normals[i]);
    for j := 0 to 3 do
    begin
    glTexCoord2fv(@TexCoord[j]);
    glVertex3fv(@Vertices[Quads[i, j]]);
    end;
    glEnd; // GL_QUADS
    end;
    glDisable(GL_TEXTURE_2D);
    end;
    [/pascal]

    Guess I have to refresh my memory a bit before moving on to the good stuff...
    If you develop an idiot proof system, the nature develops better idiots.

  5. #5

    OpenGL: Silly texturing problem

    Hint: You should check glGetError from time to time (e.g. after rendering every frame). This will automatically catch errors like this one, using some disallowed function between glBegin and glEnd.

  6. #6

    OpenGL: Silly texturing problem

    Yeah, I've already added the check to the main loop. I just couldn't think that I'd run into problems in something as trivial as this.
    If you develop an idiot proof system, the nature develops better idiots.

  7. #7

    OpenGL: Silly texturing problem

    Looks like that wasn't the end of the problems...

    For some reason I get $0502 (invalid operation) everytime I call glEnd()...

    Even something as simple as this won't work:
    [pascal]
    glBegin(GL_QUADS);
    glColor3f(0.0, 1.0, 0.0);
    glVertex3f( 1.0, 1.0,-1.0);
    glVertex3f(-1.0, 1.0,-1.0);
    glVertex3f(-1.0, 1.0, 1.0);
    glVertex3f( 1.0, 1.0, 1.0);
    glEnd();
    [/pascal]
    If you develop an idiot proof system, the nature develops better idiots.

  8. #8

    OpenGL: Silly texturing problem

    Quote Originally Posted by vgo
    Even something as simple as this won't work:
    ...
    This looks like a good code, OpenGL shouldn't complain about this. So the error must be somewhere else. Can you show complete code that doesn't work ?

    Also you can always check glGetError more often, this should give you more precise hints which operation is invalid. (But remember that glGetError is not allowed between glBegin...glEnd, so you can't put it there).

  9. #9

    OpenGL: Silly texturing problem

    Try GLexpert
    There are only 10 types of people in this world; those who understand binary and those who don't.

  10. #10

    OpenGL: Silly texturing problem

    Here's the simplified rendering code that still produces the error.
    [pascal]
    procedure glCheckForError;
    var
    glError: TGLenum;
    begin
    glError := glGetError();
    if (glError <> GL_NO_ERROR) then
    raise EOpenGLError.Create('OpenGL error! Code: ' +
    IntToStr(glError) + ' ($' + IntToHex(glError, 4) + ' hex) Description: ' +
    gluErrorString(glError));
    end;

    procedure Init;
    begin
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    glCullFace(GL_BACK);
    glFrontFace(GL_CCW);
    glShadeModel(GL_SMOOTH);
    glMatrixMode(GL_MODELVIEW);
    end;

    procedure Render;
    begin
    glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

    glRotatef(-FCamera.Pitch, 1, 0, 0);
    glRotatef(-FCamera.Yaw, 0, 1, 0);
    glTranslatef(-FCamera.Pos.x, -FCamera.Pos.y, -FCamera.Pos.z);
    glCheckForError(); // Everything is ok here

    glBegin(GL_QUADS);
    glColor3f(0.0, 1.0, 0.0);
    glVertex3f( 1.0, 1.0,-1.0);
    glVertex3f(-1.0, 1.0,-1.0);
    glVertex3f(-1.0, 1.0, 1.0);
    glVertex3f( 1.0, 1.0, 1.0);
    glEnd();
    glCheckForError(); // $0502 GL_INVALID_OPERATION here
    end;
    [/pascal]

    Rendering actually works and everything is rendered correctly, but I just always get the error from each glEnd() call. Doesn't matter what primitives I try to draw, quads, triangles, lines, points, it's all the same...

    I'm using the latest version of dglOpenGL and I use a custom panel component for rendering. I have Radeon 9800Pro with latest drivers, running on WinXP corporate edition with all latest patches. I'm using Borland Developer Studio 2006 Architect to write the code.

    Quote Originally Posted by Clootie
    Try GLexpert
    What's that?
    If you develop an idiot proof system, the nature develops better idiots.

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
  •