opengl

This is a discussion on opengl within the Game Programming forums, part of the General Programming Boards category; Hi all! I'm still learning OpenGL, but i seem to have stumbled on one little problem along the way. I'm ...

  1. #1
    Registered User Sunny's Avatar
    Join Date
    Nov 2001
    Posts
    101

    opengl

    Hi all!
    I'm still learning OpenGL, but i seem to have stumbled on one little problem along the way. I'm compiling using Bloodshed Dev C++ 4, and using a tutorial from the famous NEHE,
    i seem to be able to create nothing but an empty window. ( it's transparent).

    So...if anyone wanna tell me what's wrong with the code....




    Stef


    Discover the XBlue enviornment.
    http://www.angelfire.com/my/bahairomania/freegui.html
    Attached Files Attached Files

  2. #2
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Post You need to change something...

    In DrawGLScene(), where you draw everything, you should change glTranslatef(-1.5f, 0.0f, 0.0f); to glTranslatef(-1.5f, 0.0f, -5.0f); so that it is "zoomed" into visibility. The -5.0f is the Z-Axis, which I always remember as 'Z'oom
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  3. #3
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    there are several errors, first you don't aquire a Device Context or a Rendering Context, you never setup the pixel format, and you never set the viewport.

    i recommend reading over the original tutorial again and GL cannot function without these things.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  4. #4
    Registered User Sunny's Avatar
    Join Date
    Nov 2001
    Posts
    101

    thanks

    Thanks guys for taking your time to help. This could mean a lot to me.

    Thanks a lot.

    Stef

  5. #5
    Registered User Sunny's Avatar
    Join Date
    Nov 2001
    Posts
    101

    mmm

    Ok. I fixed the Major bugs about the Device Handle and the PIxel Format Descriptor. I can actually draw things and see them- or at least parts of them. The first time i noticed i was using Translated(..) but then i noticed the tutorial used Translatef(...) .. What could the difference be about.

    Also, I added this code to the DrawGLScene function, and when I try to zoom-out on the z coordonate with Translatef
    i can't see anything. That is, if exceed -1.0f or 1.0f. So if, I got to 1.1 or -1.1 i see a big black window and no objects. Otherwise, if i leave things alone, i can see only half side of each object...I know this sounds a little crazy, but i need help....

    Basically, all i need to know is how to zoom out so i can see both objects fully?

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glTranslatef(-1.5f, 0.0f, 0.9f);
    glBegin(GL_TRIANGLES);
    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3f( 0.0f, 1.0f, 0.0f);
    glColor3f(0.0f, 1.0f, 0.0f);
    glVertex3f( -1.0f,-1.0f, 0.0f);
    glColor3f(0.0f, 0.0f, 1.0f);
    glVertex3f( 1.0f, -1.0f, 0.0f);
    glEnd();

    glTranslatef(3.0f, 0.0f, 0.0f);
    glColor3f(0.5f,0.5f,1.0f); // Set The Color To Blue One Time Only
    glBegin(GL_QUADS); // Start Drawing Quads
    glVertex3f(-1.0f, 1.0f, 0.0f); // Left And Up 1 Unit (Top Left)
    glVertex3f( 1.0f, 1.0f, 0.0f); // Right And Up 1 Unit (Top Right)
    glVertex3f( 1.0f,-1.0f, 0.0f); // Right And Down One Unit (Bottom Right)
    glVertex3f(-1.0f,-1.0f, 0.0f); // Left And Down One Unit (Bottom Left)
    glEnd();
    glPopMatrix();
    return TRUE;
    Stef

  6. #6
    Unregistered
    Guest
    tell me if this works?

    Code:
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glPushMatrix(); // added: pushes matrix otherwise the glPopMatrix call will cause a stack underflow
    
    // Adjusted so it works for me
    glTranslatef(-1.5f, 0.0f,-5.0f);
    
    glBegin(GL_TRIANGLES);
        glColor3f(1.0f, 0.0f, 0.0f);
        glVertex3f( 0.0f, 1.0f, 0.0f);
        glColor3f(0.0f, 1.0f, 0.0f);
        glVertex3f( -1.0f,-1.0f, 0.0f);
        glColor3f(0.0f, 0.0f, 1.0f);
        glVertex3f( 1.0f, -1.0f, 0.0f);
    glEnd();
    
    glTranslatef(3.0f, 0.0f, 0.0f);
    glColor3f(0.5f,0.5f,1.0f); // Set The Color To Blue One Time Only
    
    glBegin(GL_QUADS); // Start Drawing Quads
        glVertex3f(-1.0f, 1.0f, 0.0f); // Left And Up 1 Unit (Top Left)
        glVertex3f( 1.0f, 1.0f, 0.0f); // Right And Up 1 Unit (Top Right)
        glVertex3f( 1.0f,-1.0f, 0.0f); // Right And Down One Unit (Bottom Right)
        glVertex3f(-1.0f,-1.0f, 0.0f); // Left And Down One Unit (Bottom Left)
    glEnd();
    glPopMatrix();
    if not then post your resize code and the GL init code.

  7. #7
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    pooi forgot to log in, and i ment to mention you had a stack underflow by Poping the modelview matrix withoutpushing it first. while GL guarantees no internal error will cause it to fail its just not good practice.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 11:17 AM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM
  3. OpenGL .dll vs video card dll
    By Silvercord in forum Game Programming
    Replies: 14
    Last Post: 02-12-2003, 07:57 PM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 11:14 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21