Problem with OpenGL tutorial

This is a discussion on Problem with OpenGL tutorial within the Windows Programming forums, part of the Platform Specific Boards category; Ok, I know a little on C++ and I have decided to learn OpenGL and Windows programming. However, in the ...

  1. #1
    C++ newbie
    Join Date
    Sep 2004
    Posts
    9

    Problem with OpenGL tutorial

    Ok, I know a little on C++ and I have decided to learn OpenGL and Windows programming. However, in the source code of the fourth OpenGL tutorial on this site ( http://www.cprogramming.com/tutorial/gl4.html ) there says that the file stdafx is included, and I can't find it. Is it a standard file or is it available at this site for download? By the way, I'm using Dev-C++.
    Thanks
    2Biaz

  2. #2
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    stdafx is basically a MSVC++ thing.

    I dont really think you'll need it.

    Take out that include and the #pragma statement and it should work.

    If you run into something not working let me know and we'll figure it out
    What is C++?

  3. #3
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,801
    Its not a standard header it is a vc++ header if you want to read some extra win32 tuts check out http://winprog.org
    Woop?

  4. #4
    C++ newbie
    Join Date
    Sep 2004
    Posts
    9
    This is weird. When I try to compile that code with Visual C++ 6.0 i get these errors:

    --------------------Configuration: 1424sfsdfd - Win32 Debug--------------------
    Compiling...
    dasd.cpp
    c:\documents and settings\tobias\mina dokument\spel\bwg\opengl\1424sfsdfd\dasd.cpp(5) : fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
    Error executing cl.exe.

    dasd.obj - 1 error(s), 0 warning(s)

    so i must be doin something wrong.

  5. #5
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Did you create an empty project?

    I think if you will create a new Project/Solution And make sure its not an empty project.

    If i remember right from the beta, this file is usually created with a new project.

    But even so, I dont think you'll need it.
    What is C++?

  6. #6
    C++ newbie
    Join Date
    Sep 2004
    Posts
    9
    I created a new Win32 project.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    > I'm using Dev-C++.
    Simply delete
    #include "stdafx.h"
    from your source code.

    If someone put some useful stuff inside a stdafx.h you don't have, then the code is broken
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    C++ newbie
    Join Date
    Sep 2004
    Posts
    9
    i alredy tried to remove it, but it was broken.
    Also I tried to compile some tutorials in vc++ 6 , but they gave no errors when compiling. When building however gave like 15 or 23 errors. Weird.
    Do you know any tutorials that'll work for dev-c++?

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    > but they gave no errors when compiling. When building however gave like 15 or 23 errors. Weird.
    Not really - most code you find is far more compiler specific than it ought to be
    You could post some code and some errors, it might be an easy fix
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    C++ newbie
    Join Date
    Sep 2004
    Posts
    9
    i will, however how do you post the source? i mean like is it [source][/source] or something? By the way, nice avatar and title Salem

  11. #11
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    Yes, read the posting code message at the top of the forum
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  12. #12
    C++ newbie
    Join Date
    Sep 2004
    Posts
    9
    Code:
    /*      Steven Billington
            January 13, 2003
            May 26, 2003 - UPDATE
            RobotOGL.cpp
            rod@cprogramming.com
    
            The following program creates a window and then
            uses multiple OpenGL functions to display a
            animated robot constructed of different size
            cubes. To compile this code you must make the
            proper library links in project--->settings.
    
            I apologize for any amount of scatterd code or
            mis-formatting that printing this may occur. Please
            feel free to email me at the address above for the .cpp
            file.
    */
    
    /*      These are what we refer to as Pre-processor
            Directives. In order for certain functions in
            C++ to operate you must include certain header
            files. Each header file below contains different
            functions needed throughout this program.
    */
    
    #pragma comment(linker, "/subsystem:windows")
    
    #include <windows.h>
    #include <gl/gl.h>
    #include <gl/glu.h>
    #include <gl/glaux.h>
    
    /*      Here we find a few global variables. While
            i don't really like to use global variables,
            i found them very handy for this particular
            program. These variables will control angles,
            fullscreen, and the global device context.
    */
    
    HDC g_HDC;
    float angle = 0.0f;
    float legAngle[2] = {0.0f, 0.0f};
    float armAngle[2] = {0.0f, 0.0f};
    bool fullScreen = false;
    
    /*      Function:       DrawCube
            Purpose:        As the name would suggest, this is
                                    the function for drawing the cubes.
    */
    
    void DrawCube(float xPos, float yPos, float zPos)
    {
            glPushMatrix();
            glBegin(GL_POLYGON);
    
                    /*      This is the top face*/
                    glVertex3f(0.0f, 0.0f, 0.0f);
                    glVertex3f(0.0f, 0.0f, -1.0f);
                    glVertex3f(-1.0f, 0.0f, -1.0f);
                    glVertex3f(-1.0f, 0.0f, 0.0f);
    
                    /*      This is the front face*/
                    glVertex3f(0.0f, 0.0f, 0.0f);
                    glVertex3f(-1.0f, 0.0f, 0.0f);
                    glVertex3f(-1.0f, -1.0f, 0.0f);
                    glVertex3f(0.0f, -1.0f, 0.0f);
    
                    /*      This is the right face*/
                    glVertex3f(0.0f, 0.0f, 0.0f);
                    glVertex3f(0.0f, -1.0f, 0.0f);
                    glVertex3f(0.0f, -1.0f, -1.0f);
                    glVertex3f(0.0f, 0.0f, -1.0f);
    
                    /*      This is the left face*/
                    glVertex3f(-1.0f, 0.0f, 0.0f);
                    glVertex3f(-1.0f, 0.0f, -1.0f);
                    glVertex3f(-1.0f, -1.0f, -1.0f);
                    glVertex3f(-1.0f, -1.0f, 0.0f);
    
                    /*      This is the bottom face*/
                    glVertex3f(0.0f, 0.0f, 0.0f);
                    glVertex3f(0.0f, -1.0f, -1.0f);
                    glVertex3f(-1.0f, -1.0f, -1.0f);
                    glVertex3f(-1.0f, -1.0f, 0.0f);
    
                    /*      This is the back face*/
                    glVertex3f(0.0f, 0.0f, 0.0f);
                    glVertex3f(-1.0f, 0.0f, -1.0f);
                    glVertex3f(-1.0f, -1.0f, -1.0f);
                    glVertex3f(0.0f, -1.0f, -1.0f);
    
            glEnd();
            glPopMatrix();
    }
    
    /*      Function:       DrawArm
            Purpose:        This function draws the arm
                                    for the robot.
    */
    
    void DrawArm(float xPos, float yPos, float zPos)
    {
            glPushMatrix();
    
                    /*      Sets color to red*/
                    glColor3f(1.0f, 0.0f, 0.0f);
                    glTranslatef(xPos, yPos, zPos);
    
                    /*      Creates 1 x 4 x 1 cube*/
                    glScalef(1.0f, 4.0f, 1.0f);
                    DrawCube(0.0f, 0.0f, 0.0f);
    
            glPopMatrix();
    }
    
    /*      Function:       DrawHead
            Purpose:        This function will create the
                                    head for the robot.
    */
    
    void DrawHead(float xPos, float yPos, float zPos)
    {
            glPushMatrix();
    
                    /*      Sets color to white*/
                    glColor3f(1.0f, 1.0f, 1.0f);
                    glTranslatef(xPos, yPos, zPos);
    
                    /*      Creates 2 x 2 x 2 cube*/
                    glScalef(2.0f, 2.0f, 2.0f);
                    DrawCube(0.0f, 0.0f, 0.0f);
    
            glPopMatrix();
    }
    
    /*      Function:       DrawTorso
            Purpose:        Function will do as suggested
                                    and draw a torso for our robot.
    */
    
    void DrawTorso(float xPos, float yPos, float zPos)
    {
            glPushMatrix();
    
                    /*      Sets color to blue*/
                    glColor3f(0.0f, 0.0f, 1.0f);
                    glTranslatef(xPos, yPos, zPos);
    
                    /*      Creates 3 x 5 x 1 cube*/
                    glScalef(3.0f, 5.0f, 1.0f);
                    DrawCube(0.0f, 0.0f, 0.0f);
    
            glPopMatrix();
    }
    
    /*      Function:       DrawLeg
            Purpose:        Not to sound repetitve, but as suggested
                                    this function will draw our robots legs.
    */
    
    void DrawLeg(float xPos, float yPos, float zPos)
    {
            glPushMatrix();
    
                    /*      Sets color to yellow*/
                    glColor3f(1.0f, 1.0f, 0.0f);
                    glTranslatef(xPos, yPos, zPos);
    
                    /*      Creates 1 x 5 x 1 cube*/
                    glScalef(1.0f, 5.0f, 1.0f);
                    DrawCube(0.0f, 0.0f, 0.0f);
    
            glPopMatrix();
    }
    
    /*      Function:       DrawRobot
            Purpose:        Function to draw our entire robot
    */
    
    void DrawRobot(float xPos, float yPos, float zPos)
    {
            /*      Variables for state of robots legs. True
                    means the leg is forward, and False means
                    the leg is back. The same applies to the
                    robots arm states.
            */
            static bool leg1 = true;
            static bool leg2 = false;
            static bool arm1 = true;
            static bool arm2 = false;
    
            glPushMatrix();
    
                    /*      This will draw our robot at the
                            desired coordinates.
                    */
                    glTranslatef(xPos, yPos, zPos);
    
                    /*      These three lines will draw the
                            various components of our robot.
                    */
                    DrawHead(1.0f, 2.0f, 0.0f);
                    DrawTorso(1.5f, 0.0f, 0.0f);
                    glPushMatrix();
    
    
                    /*      If the arm is moving forward we will increase
                            the angle; otherwise, we will decrease the
                            angle.
                    */
                    if (arm1)
                    {
                            armAngle[0] = armAngle[0] + 1.0f;
                    }
                    else
                    {
                            armAngle[0] = armAngle[0] - 1.0f;
                    }
    
                    /*      Once the arm has reached its max angle
                            in one direction, we want it to reverse
                            and change direction.
                    */
                    if (armAngle[0] >= 15.0f)
                    {
                            arm1 = false;
                    }
                    if (armAngle[0] <= 15.0f)
                    {
                            arm1 = true;
                    }
    
    
                    /*      Here we are going to move the arm away
                            from the torso and rotate. This will
                            create a walking effect.
                    */
                    glTranslatef(0.0f, -0.5f, 0.0f);
                    glRotatef(armAngle[0], 1.0f, 0.0f, 0.0f);
                    DrawArm(2.5f, 0.0f, -0.5f);
    
            glPopMatrix();
    
            glPushMatrix();
    
    
                    /*      If the arm is moving forward we will increase
                            the angle, otherwise we will decrease the
                            angle
                    */
                    if (arm2)
                    {
                            armAngle[1] = armAngle[1] + 1.0f;
                    }
                    else
                    {
                            armAngle[1] = armAngle[1] - 1.0f;
                    }
    
                    /*      Here we are going to move the arm away
                            from the torso and rotate. This will
                            create a walking effect.
                    */
                    glTranslatef(0.0f, -0.5f, 0.0f);
                    glRotatef(armAngle[1], 1.0f, 0.0f, 0.0f);
                    DrawArm(-1.5f, 0.0f, -0.5f);
    
            glPopMatrix();
    
            /*      Now its time to rotate the legs relative to the
                    robots position in the world, this is the first
                    leg, ie the right one.
            */
            glPushMatrix();
    
                    /*      If the leg is moving forward we will increase
                            the angle; otherwise, we will decrease the
                            angle.
                    */
                    if (leg1)
                    {
                            legAngle[0] = legAngle[0] + 1.0f;
                    }
                    else
                    {
                            legAngle[0] = legAngle[0] - 1.0f;
                    }
    
                    /*      Once the leg has reached its max angle
                            in one direction, we want it to reverse
                            and change direction.
                    */
                    if (legAngle[0] >= 15.0f)
                    {
                            leg1 = false;
                    }
                    if (legAngle[0] <= -15.0f)
                    {
                            leg1 = true;
                    }
    
    
                    /*      Here we are going to move the leg away
                            from the torso and rotate. This will
                            create a walking effect.
                    */
                    glTranslatef(0.0f, -0.5f, 0.0f);
                    glRotatef(legAngle[0], 1.0f, 0.0f, 0.0f);
    
    
                    /*      Time to draw the leg.
                    */
                    DrawLeg(-0.5f, -5.0f, -0.5f);
    
            glPopMatrix();
    
            /*      Same as above, for the left leg.
            */
            glPushMatrix();
    
                    /*      If the leg is moving forward we will increase
                            the angle, otherwise we will decrease the
                            angle
                    */
                    if (leg2)
                    {
                            legAngle[1] = legAngle[1] + 1.0f;
                    }
                    else
                    {
                            legAngle[1] = legAngle[1] - 1.0f;
                    }
    
                    /*      Once the leg has reached its max angle
                            in one direction, we want it to reverse
                            and change direction.
                    */
                    if (legAngle[1] >= 15.0f)
                    {
                            leg2 = false;
                    }
                    if (legAngle[1] <= -15.0f)
                    {
                            leg2 = true;
                    }
    
                    /*      Here we are going to move the leg away
                            from the torso and rotate. This will
                            create a walking effect.
                    */
                    glTranslatef(0.0f, -0.5f, 0.0f);
                    glRotatef(legAngle[1], 1.0f, 0.0f, 0.0f);
                    DrawLeg(1.5f, -5.0f, -0.5f);
    
            glPopMatrix();
    
            glPopMatrix();
    
    }
    
    /*      Function:       Render
            Purpose:        This function will be responsible
                                    for the rendering, got to love my
                                    descriptive function names : )
    */
    void Render()
    {
            /*      Enable depth testing
            */
            glEnable(GL_DEPTH_TEST);
    
            /*      Heres our rendering. Clears the screen
                    to black, clear the color and depth
                    buffers, and reset our modelview matrix.
            */
            glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            glLoadIdentity();
    
            /*      Increase rotation angle counter
            */
            angle = angle + 1.0f;
    
            /*      Reset after we have completed a circle
            */
            if (angle >= 360.0f)
            {
                    angle = 0.0f;
            }
    
            glPushMatrix();
                    glLoadIdentity();
    
                    /*      Move to 0,0,-30 , rotate the robot on
                            its y axis, draw the robot, and dispose
                            of the current matrix.
                    */
                    glTranslatef(0.0f, 0.0f, -30.0f);
                    glRotatef(angle, 0.0f, 1.0f, 0.0f);
                    DrawRobot(0.0f, 0.0f, 0.0f);
            glPopMatrix();
    
            glFlush();
    
            /*      Bring back buffer to foreground
            */
            SwapBuffers(g_HDC);
    }
    
    //function to set the pixel format for the device context
    /*      Function:       SetupPixelFormat
            Purpose:        This function will be responsible
                                    for setting the pixel format for the
                                    device context.
    */
    void SetupPixelFormat(HDC hDC)
    {
            /*      Pixel format index
            */
            int nPixelFormat;
    
            static PIXELFORMATDESCRIPTOR pfd = {
                    sizeof(PIXELFORMATDESCRIPTOR),          //size of structure
                    1,                                      //default version
                    PFD_DRAW_TO_WINDOW |                    //window drawing support
                    PFD_SUPPORT_OPENGL |                    //opengl support
                    PFD_DOUBLEBUFFER,                       //double buffering support
                    PFD_TYPE_RGBA,                          //RGBA color mode
                    32,                                     //32 bit color mode
                    0, 0, 0, 0, 0, 0,                       //ignore color bits
                    0,                                      //no alpha buffer
                    0,                                      //ignore shift bit
                    0,                                      //no accumulation buffer
                    0, 0, 0, 0,                             //ignore accumulation bits
                    16,                                     //16 bit z-buffer size
                    0,                                      //no stencil buffer
                    0,                                      //no aux buffer
                    PFD_MAIN_PLANE,                         //main drawing plane
                    0,                                      //reserved
                    0, 0, 0 };                              //layer masks ignored
    
                    /*      Choose best matching format*/
                    nPixelFormat = ChoosePixelFormat(hDC, &pfd);
    
                    /*      Set the pixel format to the device context*/
                    SetPixelFormat(hDC, nPixelFormat, &pfd);
    }
    
    /*      Windows Event Procedure Handler
    */
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
            /*      Rendering and Device Context
                    variables are declared here.
            */
            static HGLRC hRC;
            static HDC hDC;
    
            /*      Width and Height for the
                    window our robot is to be
                    displayed in.
            */
            int width, height;
    
            switch(message)
            {
                    case WM_CREATE: //window being created
    
                            hDC = GetDC(hwnd);  //get current windows device context
                            g_HDC = hDC;
                            SetupPixelFormat(hDC); //call our pixel format setup function
    
                            /*      Create rendering context and make it current
                            */
                            hRC = wglCreateContext(hDC);
                            wglMakeCurrent(hDC, hRC);
    
                            return 0;
                            break;
    
                    case WM_CLOSE:  //window is closing
    
                            /*      Deselect rendering context and delete it*/
                            wglMakeCurrent(hDC, NULL);
                            wglDeleteContext(hRC);
    
                            /*      Send quit message to queue*/
                            PostQuitMessage(0);
    
                            return 0;
                            break;
    
                    case WM_SIZE:
    
                            /*      Retrieve width and height*/
                            height = HIWORD(lParam);
                            width = LOWORD(lParam);
    
                            /*      Don't want a divide by 0*/
                            if (height == 0)
                            {
                                    height = 1;
                            }
    
                            /*      Reset the viewport to new dimensions*/
                            glViewport(0, 0, width, height);
    
                            /*      Set current Matrix to projection*/
                            glMatrixMode(GL_PROJECTION);
                            glLoadIdentity(); //reset projection matrix
    
                            /*      Time to calculate aspect ratio of
                                    our window.
                            */
                            gluPerspective(54.0f, (GLfloat)width/(GLfloat)height, 1.0f, 1000.0f);
    
                            glMatrixMode(GL_MODELVIEW); //set modelview matrix
                            glLoadIdentity(); //reset modelview matrix
    
                            return 0;
                            break;
    
                    default:
    
                            break;
            }
    
            return (DefWindowProc(hwnd, message, wParam, lParam));
    }
    
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
            WNDCLASSEX windowClass; //window class
            HWND    hwnd;                   //window handle
            MSG             msg;                    //message
            bool    done;                   //flag for completion of app
            DWORD   dwExStyle;              //window extended style
            DWORD   dwStyle;                //window style
            RECT    windowRect;
    
            /*      Screen/display attributes*/
            int width = 800;
            int height = 600;
            int bits = 32;
    
            windowRect.left =(long)0;               //set left value to 0
            windowRect.right =(long)width;  //set right value to requested width
            windowRect.top =(long)0;                //set top value to 0
            windowRect.bottom =(long)height;//set bottom value to requested height
    
            /*      Fill out the window class structure*/
            windowClass.cbSize                      = sizeof(WNDCLASSEX);
            windowClass.style                       = CS_HREDRAW | CS_VREDRAW;
            windowClass.lpfnWndProc         = WndProc;
            windowClass.cbClsExtra          = 0;
            windowClass.cbWndExtra          = 0;
            windowClass.hInstance           = hInstance;
            windowClass.hIcon                       = LoadIcon(NULL, IDI_APPLICATION);
            windowClass.hCursor                     = LoadCursor(NULL, IDC_ARROW);
            windowClass.hbrBackground       = NULL;
            windowClass.lpszMenuName        = NULL;
            windowClass.lpszClassName       = "MyClass";
            windowClass.hIconSm                     = LoadIcon(NULL, IDI_WINLOGO);
    
            /*      Register window class*/
            if (!RegisterClassEx(&windowClass))
            {
                    return 0;
            }
    
            /*      Check if fullscreen is on*/
            if (fullScreen)
            {
                    DEVMODE dmScreenSettings;
                    memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
                    dmScreenSettings.dmSize = sizeof(dmScreenSettings);
                    dmScreenSettings.dmPelsWidth = width;   //screen width
                    dmScreenSettings.dmPelsHeight = height; //screen height
                    dmScreenSettings.dmBitsPerPel = bits;   //bits per pixel
                    dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
    
                    if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN !=
                                                                      DISP_CHANGE_SUCCESSFUL))
                    {
                            /*      Setting display mode failed, switch to windowed*/
                            MessageBox(NULL, "Display mode failed", NULL, MB_OK);
                            fullScreen = false;
                    }
            }
    
            /*      Check if fullscreen is still on*/
            if (fullScreen)
            {
                    dwExStyle = WS_EX_APPWINDOW;    //window extended style
                    dwStyle = WS_POPUP;                             //windows style
                    ShowCursor(FALSE);                              //hide mouse pointer
            }
    
            else
            {
                    dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; //window extended style
                    dwStyle = WS_OVERLAPPEDWINDOW;                                  //windows style
            }
    
            AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);
    
            /*      Class registerd, so now create our window*/
            hwnd = CreateWindowEx(NULL, "MyClass",  //class name
                                                      "OpenGL Robot",       //app name
                                                      dwStyle |
                                                      WS_CLIPCHILDREN |
                                                      WS_CLIPSIBLINGS,
                                                      0, 0,                         //x and y coords
                                                      windowRect.right - windowRect.left,
                                                      windowRect.bottom - windowRect.top,//width, height
                                                      NULL,                 //handle to parent
                                                      NULL,                 //handle to menu
                                                      hInstance,    //application instance
                                                      NULL);                //no xtra params
    
            /*      Check if window creation failed (hwnd = null ?)*/
            if (!hwnd)
            {
                    return 0;
            }
    
            ShowWindow(hwnd, SW_SHOW);      //display window
            UpdateWindow(hwnd);                     //update window
    
            done = false;   //initialize loop condition variable
    
            /*      Main message loop*/
            while (!done)
            {
                    PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE);
    
                            if (msg.message == WM_QUIT)     //did we revieve a quit message?
                            {
                                    done = true;
                            }
    
                            else
                            {
                                    Render();
                                    TranslateMessage(&msg);
                                    DispatchMessage(&msg);
                            }
            }
    
            if (fullScreen)
            {
                    ChangeDisplaySettings(NULL, 0);
                    ShowCursor(TRUE);
            }
    
            return msg.wParam;
    
    }
    That's the code, I think I found it on this site but i'm not sure.

    Compiler says:
    --------------------Configuration: 14124134 - Win32 Debug--------------------
    Compiling...
    Skipping... (no relevant changes detected)
    auhl.cpp

    auhl.obj - 0 error(s), 0 warning(s)

    When I build it says:
    --------------------Configuration: 14124134 - Win32 Debug--------------------
    Linking...
    auhl.obj : error LNK2001: unresolved external symbol __imp__glPopMatrix@0
    auhl.obj : error LNK2001: unresolved external symbol __imp__glEnd@0
    auhl.obj : error LNK2001: unresolved external symbol __imp__glVertex3f@12
    auhl.obj : error LNK2001: unresolved external symbol __imp__glBegin@4
    auhl.obj : error LNK2001: unresolved external symbol __imp__glPushMatrix@0
    auhl.obj : error LNK2001: unresolved external symbol __imp__glScalef@12
    auhl.obj : error LNK2001: unresolved external symbol __imp__glTranslatef@12
    auhl.obj : error LNK2001: unresolved external symbol __imp__glColor3f@12
    auhl.obj : error LNK2001: unresolved external symbol __imp__glRotatef@16
    auhl.obj : error LNK2001: unresolved external symbol __imp__glFlush@0
    auhl.obj : error LNK2001: unresolved external symbol __imp__glLoadIdentity@0
    auhl.obj : error LNK2001: unresolved external symbol __imp__glClear@4
    auhl.obj : error LNK2001: unresolved external symbol __imp__glClearColor@16
    auhl.obj : error LNK2001: unresolved external symbol __imp__glEnable@4
    auhl.obj : error LNK2001: unresolved external symbol _gluPerspective@32
    auhl.obj : error LNK2001: unresolved external symbol __imp__glMatrixMode@4
    auhl.obj : error LNK2001: unresolved external symbol __imp__glViewport@16
    auhl.obj : error LNK2001: unresolved external symbol __imp__wglDeleteContext@4
    auhl.obj : error LNK2001: unresolved external symbol __imp__wglMakeCurrent@8
    auhl.obj : error LNK2001: unresolved external symbol __imp__wglCreateContext@4
    Debug/14124134.exe : fatal error LNK1120: 20 unresolved externals
    Error executing link.exe.

    14124134.exe - 21 error(s), 0 warning(s)


    Do you have any idea why?

  13. #13
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Those errors specify that the functions can not be found. You need to link with the correct library. To find the library needed for a function, look up the function in MSDN and you will find something like this at the bottom of the page:
    Windows NT/2000/XP: Included in Windows NT 3.1 and later.
    Windows 95/98/Me: Included in Windows 95 and later.
    Header: Declared in Wingdi.h; include Windows.h.
    Library: Use Gdi32.lib.
    Then add the required library to your project. The easiest way to do this in Visual C++ is to add a pragma directive to your code:
    Code:
    #pragma comment(lib, "gdi32.lib")
    #pragma comment(lib, "user32.lib")

  14. #14
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Same idea with dev-cpp (mingw) - link with the correct libs (-lopengl32 and -glu32). Also remove/comment out msvc specific stuff, such as the #pragmas; #include <glaux.h> is also one included header too many; that should just about do it with respect to dev-cpp and the code you posted.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  15. #15
    C++ newbie
    Join Date
    Sep 2004
    Posts
    9
    Sorry if this is dumb, but how do I link with libs? I tried to remove the #include <gl/glaux.h>
    and i inserted this instead:
    Code:
    #pragma comment(lib, "opengl32.lib")
    #pragma comment(lib, "glu32.lib")
    but its still giving me the same errors.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. first opengl game, problems.
    By n3v in forum Game Programming
    Replies: 1
    Last Post: 07-11-2006, 08:22 PM
  2. Newbie opengl display problem.
    By godhand in forum Game Programming
    Replies: 1
    Last Post: 03-29-2004, 06:25 AM
  3. OpenGl 2D Tiling problem
    By werdy666 in forum Game Programming
    Replies: 1
    Last Post: 09-29-2002, 11:48 PM
  4. Problem running a Cboard C++ tutorial!
    By Monkey Liar in forum C++ Programming
    Replies: 6
    Last Post: 02-15-2002, 02:32 AM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 09:01 PM

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