Archived

This topic is now archived and is closed to further replies.

Bert I

OpenGL Setting Up OpenGL for Dev-C++

Recommended Posts

How do you use OpenGL with Dev-C++? I've setup GLUT (I hope I set it up right). But when I tried to compile a OpenGL program it gave errors in the GL/gl.h file in the place with alot of 'void' things. I've included the files 'iostream', 'GL/gl.h', and 'GL/glut.h'. Here is the code I used.
      
#include <iostream>    // Standard Header For Most Programs
#include <GL/gl.h>      // The GL Header File
#include <GL/glut.h>    // The GL Utility Toolkit (Glut) Header
 

void init ( GLvoid )     // Create Some Everyday Functions

{
 
  glShadeModel(GL_SMOOTH);                        // Enable Smooth Shading

                    glClearColor(0.0f, 0.0f, 0.0f, 0.5f);    // Black Background

                    glClearDepth(1.0f);                                                // Depth Buffer Setup

                    glEnable(GL_DEPTH_TEST);                             // Enables Depth Testing

                    glDepthFunc(GL_LEQUAL);                              // The Type Of Depth Testing To Do

   glEnable ( GL_COLOR_MATERIAL );
   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
 
void display ( void )   // Create The Display Function

{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);      // Clear Screen And Depth Buffer

                    glLoadIdentity();                                                                                                                                     // Reset The Current Modelview Matrix

                    glTranslatef(-1.5f,0.0f,-6.0f);            // Move Left 1.5 Units And Into The Screen 6.0

                    glBegin(GL_TRIANGLES);             // Drawing Using Triangles

                                         glVertex3f( 0.0f, 1.0f, 0.0f);  // Top

                                         glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left

                                         glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right

                    glEnd();                                                                                                                                                                                                                  // Finished Drawing The Triangle

                    glTranslatef(3.0f,0.0f,0.0f);               // Move Right 3 Units

                    glBegin(GL_QUADS);                                                                                                                                                                    // Draw A Quad

                                         glVertex3f(-1.0f, 1.0f, 0.0f);               // Top Left

                                         glVertex3f( 1.0f, 1.0f, 0.0f);               // Top Right

                                         glVertex3f( 1.0f,-1.0f, 0.0f)                // Bottom Right

                                         glVertex3f(-1.0f,-1.0f, 0.0f);               // Bottom Left

                    glEnd();
 
  glutSwapBuffers ( );    // Swap The Buffers To Not Be Left With A Clear Screen

}
 
 
 
void reshape ( int w, int h )   // Create The Reshape Function (the viewport)

{
  glViewport     ( 0, 0, w, h );
  glMatrixMode   ( GL_PROJECTION );             // Select The Projection Matrix

  glLoadIdentity ( );                // Reset The Projection Matrix

  if ( h==0 )  // Calculate The Aspect Ratio Of The Window

     gluPerspective ( 80, ( float ) w, 1.0, 5000.0 );
  else
     gluPerspective ( 80, ( float ) w / ( float ) h, 1.0, 5000.0 );
  glMatrixMode   ( GL_MODELVIEW );  // Select The Model View Matrix

  glLoadIdentity ( );    // Reset The Model View Matrix

}
 
void keyboard ( unsigned char key, int x, int y )  // Create Keyboard Function

{
  switch ( key ) {
    case 27:        // When Escape Is Pressed...

      exit ( 0 );   // Exit The Program

      break;        // Ready For Next Case

    default:        // Now Wrap It Up

      break;
  }
}
 
void arrow_keys ( int a_keys, int x, int y )  // Create Special Function (required for arrow keys)

{
  switch ( a_keys ) {
    case GLUT_KEY_UP:     // When Up Arrow Is Pressed...

      glutFullScreen ( ); // Go Into Full Screen Mode

      break;
    case GLUT_KEY_DOWN:               // When Down Arrow Is Pressed...

      glutReshapeWindow ( 500, 500 ); // Go Into A 500 By 500 Window

      break;
    default:
      break;
  }
}
 
void main ( int argc, char** argv )   // Create Main Function For Bringing It All Together

{
  glutInit            ( &argc, argv ); // Erm Just Write It =)

  init ();
  glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE ); // Display Mode

  glutInitWindowSize  ( 500, 500 ); // If glutFullScreen wasn't called this is the window size

  glutCreateWindow    ( "NeHe's OpenGL Framework" ); // Window Title (argv[0] for current directory as title)

  glutFullScreen      ( );          // Put Into Full Screen

  glutDisplayFunc     ( display );  // Matching Earlier Functions To Their Counterparts

  glutReshapeFunc     ( reshape );
  glutKeyboardFunc    ( keyboard );
  glutSpecialFunc     ( arrow_keys );
  glutMainLoop        ( );          // Initialize The Main Loop

}
      
I got 367 errors so I won't list them all but most of them are something like --line - unit - message-- 1138 C:\DEV-CPP\include\GL\gl.h syntax error before `void' A couple others are --line - unit - message-- 2 C:\My Documents\Bertram\OpenGL\nehe-test.cpp In file included from C:\My Documents\Bertram\OpenGL\nehe-test.cpp 8 C:\My Documents\Bertram\OpenGL\nehe-test.cpp implicit declaration of function `int glShadeModel(...)' 9 C:\My Documents\Bertram\OpenGL\nehe-test.cpp implicit declaration of function `int glClearColor(...)' 10 C:\My Documents\Bertram\OpenGL\nehe-test.cpp implicit declaration of function `int glClearDepth(...)' 11 C:\My Documents\Bertram\OpenGL\nehe-test.cpp implicit declaration of function `int glEnable(...)' 12 C:\My Documents\Bertram\OpenGL\nehe-test.cpp implicit declaration of function `int glDepthFunc(...)' 14 C:\My Documents\Bertram\OpenGL\nehe-test.cpp implicit declaration of function `int glHint(...)' [edited by - Bert I on November 6, 2002 9:20:41 PM]

Share this post


Link to post
Share on other sites
Thanks! :-) That fixed ALOT of my errors. But there's still one left.

--line - unit - message--
33 C:\My Documents\Bertram\OpenGL\nehe-test.cpp parse error before `('

I think the error is that its missing a semi-colon ( but when I remove it it gives me 43 errors.

[edited by - Bert I on November 6, 2002 10:33:19 PM]

Share this post


Link to post
Share on other sites
There's a missing semicolon at the end of line 29 (line 29 from the text above, it may be somewhere else in your source because of forum-mangling); add one there.



[edited by - Null and Void on November 6, 2002 10:41:48 PM]

Share this post


Link to post
Share on other sites