Thread: OpenGL Not working......

  1. #1
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719

    OpenGL Not working......

    Ok, so I am trying to do some stuff in OpenGL. I got Visual C++ .net a few months ago, but I haven't tryed opengl with it yet. I was using Dev C++ for a little while and that worked fine compiling opengl code. But when i try to compile the simplest of opengl code with Visual C++ I get an error:
    Code:
     fatal error C1010: unexpected end of file while looking for precompiled header directive
    Here is the code I copied from someplace :

    Code:
    #include <GL/glut.h>
    #include "stdlib.h"
    
    #define RAMPSIZE 16
    #define RAMP1START 32
    #define RAMP2START 48
    
    static float rotAngle = 0.;
    
    /*  Initialize antialiasing for color index mode,
     *  including loading a green color ramp starting
     *  at RAMP1START, and a blue color ramp starting
     *  at RAMP2START. The ramps must be a multiple of 16.
     */
    void init(void)
    {
       int i;
    
       for (i = 0; i < RAMPSIZE; i++) {
          GLfloat shade;
          shade = (GLfloat) i/(GLfloat) RAMPSIZE;
          glutSetColor(RAMP1START+(GLint)i, 0., shade, 0.);
          glutSetColor(RAMP2START+(GLint)i, 0., 0., shade);
       }
    
       glEnable (GL_LINE_SMOOTH);
       glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
       glLineWidth (1.5);
    
       glClearIndex ((GLfloat) RAMP1START);
    }
    
    /*  Draw 2 diagonal lines to form an X
     */
    void display(void)
    {
       glClear(GL_COLOR_BUFFER_BIT);
    
       glIndexi(RAMP1START);
       glPushMatrix();
       glRotatef(-rotAngle, 0.0, 0.0, 0.1);
       glBegin (GL_LINES);
          glVertex2f (-0.5, 0.5);
          glVertex2f (0.5, -0.5);
       glEnd ();
       glPopMatrix();
    
       glIndexi(RAMP2START);
       glPushMatrix();
       glRotatef(rotAngle, 0.0, 0.0, 0.1);
       glBegin (GL_LINES);
          glVertex2f (0.5, 0.5);
          glVertex2f (-0.5, -0.5);
       glEnd ();
       glPopMatrix();
    
       glFlush();
    }
    
    void reshape(int w, int h)
    {
       glViewport(0, 0, (GLsizei) w, (GLsizei) h);
       glMatrixMode(GL_PROJECTION);
       glLoadIdentity();
       if (w <= h) 
          gluOrtho2D (-1.0, 1.0, 
             -1.0*(GLfloat)h/(GLfloat)w, 1.0*(GLfloat)h/(GLfloat)w);
       else 
          gluOrtho2D (-1.0*(GLfloat)w/(GLfloat)h, 
             1.0*(GLfloat)w/(GLfloat)h, -1.0, 1.0);
       glMatrixMode(GL_MODELVIEW);
       glLoadIdentity();
    }
    
    void keyboard(unsigned char key, int x, int y)
    {
       switch (key) {
          case 'r':
          case 'R':
             rotAngle += 20.;
             if (rotAngle >= 360.) rotAngle = 0.;
             glutPostRedisplay();	
             break;
          case 27:  /*  Escape Key */
             exit(0);
             break;
          default:
             break;
        }
    }
    
    /*  Main Loop
     *  Open window with initial window size, title bar, 
     *  color index display mode, and handle input events.
     */
    int main(int argc, char** argv)
    {
       glutInit(&argc, argv);
       glutInitDisplayMode (GLUT_SINGLE | GLUT_INDEX);
       glutInitWindowSize (200, 200);
       glutCreateWindow (argv[0]);
       init();
       glutReshapeFunc (reshape);
       glutKeyboardFunc (keyboard);
       glutDisplayFunc (display);
       glutMainLoop();
       return 0;
    }
    Help me.

  2. #2
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    I'm pretty certain you need to #include <gl/gl.h> to use some of the functions calls you use.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  3. #3
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Nah, that didn't work. Can anyone give me some reliable code? Like, some code that intializes an opengl window, in windowed mode. Thanks! Also, do I have to link anything in the configurations to be able to compile opengl programs? I hope not, because I would feel really stupid There isn't an SDK is there?

    EDIT: BTW I have the latest NVIDIA drivers installed, too.
    Last edited by Sentral; 01-17-2006 at 04:33 PM.

  4. #4
    Yah. Morgul's Avatar
    Join Date
    Feb 2005
    Posts
    109
    You have to link OpenGL library files, but that isn't your problem right now. What kind of project are you using for this? It should be a empty windows application. This is looking for precompliled headers which means you aren't using the correct project type for this.

    Plus I don't think you can run OpenGL programs like you are trying to do in the console. I don't have a lot of OpenGL experience being a DX guy, but I think you need to make a window, ie. using WinMain() etc.
    Last edited by Morgul; 01-17-2006 at 06:45 PM.
    Sic vis pacum para bellum. If you want peace, prepare for war.

  5. #5
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    I am using a win32 project. Also, I even tryed some opengl code that created a window. But when i tryed to compile it. It gave me that same error in my first post. So I DO have to link something. Well, can someone help me out there?

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I believe the answer has been duly provided. Read.

    www.amazon.com - Get a book about OpenGL.

  7. #7
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    If you are using GLUT, DON"T USE A WIN32 Project... use a regular console type one. And you probably have to have #include<windows.h> as your FIRST include.

  8. #8
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Project -> Settings -> C/C++ Tab
    From the drop-down box, select "Precompiled Headers". Now select the radio button that says "Not using precompiled headers".

    These steps may vary a little bit depending on what version of MSVC you are using.

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    In the future, when you create a project, always select Empty Project in the create wizard to avoid this problem.
    If you can't find the option bithub mentioned, you can also create a new empty project and import the source files into it.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  10. #10
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Ok, I think I got it partially working after I followed a tutorial. Turns out I had to download GLUT, and put the .dll's into the system folder. And the lib and .h in the correct directory. I also linked it in Visual C++. But now when I compile I stuff, i get different errors. I don't get the same error that I mentioned before, so it must have found the .lib and stuff. But I still get some errors.

  11. #11
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    What errors?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  12. #12
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Ok, I used the code from nehe lesson 2. Here are my errors:
    Code:
    ------ Build started: Project: dfjdj, Configuration: Debug Win32 ------
    
    Linking...
    LIBCD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup
    Debug/dfjdj.exe : fatal error LNK1120: 1 unresolved externals
    
    Build log was saved at "file://c:\Documents and Settings\tony\My Documents\Visual Studio Projects\dfjdj\Debug\BuildLog.htm"
    dfjdj - 2 error(s), 0 warning(s)
    
    
    ---------------------- Done ----------------------
    
        Build: 0 succeeded, 1 failed, 0 skipped
    Here is the tutorial I was using: HERE

  13. #13
    Yah. Morgul's Avatar
    Join Date
    Feb 2005
    Posts
    109
    It isn't expecting you to use main as your entry point for some reason in the first error.
    Sic vis pacum para bellum. If you want peace, prepare for war.

  14. #14
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    But main() is there ...
    What's your current code? Still exactly the same as in the first post?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  15. #15
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    No, I said I used nehe's lesson # 2. I downloaded the Visual C++ .net version of the code, if that's correct.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multithread pthread with OpenGL
    By parad0x13 in forum C++ Programming
    Replies: 8
    Last Post: 07-24-2008, 03:04 PM
  2. Replies: 8
    Last Post: 01-18-2008, 04:06 AM
  3. Replies: 4
    Last Post: 01-13-2008, 02:14 AM
  4. Replies: 0
    Last Post: 07-26-2007, 09:55 AM
  5. .TGA files in OpenGL
    By ... in forum Game Programming
    Replies: 2
    Last Post: 10-26-2003, 02:48 PM