[try Beta version]
Not logged in

 
OpenGl C++

Jun 20, 2013 at 1:44pm
Hi. I'd like to use opengl under Dev-C++. I downloaded and copied files from GLUT, and tried to run a test program. But here's some error:
line2-In file included from GlTest.cpp
line45-redeclaration of C++ built-in type 'short'
line39-'main must return 'int'


The test programme is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <gl/gl.h>
#include <gl/glut.h>
#include <gl/glu.h>

const int   A = 500;  /* length of a side of the monitor window */
const float B = 500;  /* length of a side of the clipping rectangle */
const float C = 200;  /* length of a side of the square the program draws */

void myinit(void)
{
  glClearColor(0.7, 0.7, 0.7, 0.0); /* gray background */
 
  glMatrixMode(GL_PROJECTION);      /* In World coordinates: */
  glLoadIdentity();                 /* position the "clipping rectangle" */
  gluOrtho2D( -B/2, B/2, -B/2, B/2);/* at -B/2, its right edge at +B/2, its bottom */
  glMatrixMode(GL_MODELVIEW);       /* edge at -B/2 and its top edge at +B/2 */
}

void display( void )
{
                                    
  glClear(GL_COLOR_BUFFER_BIT);     /* clear the window */
 
  glMatrixMode(GL_MODELVIEW);       /* The following coordinates are expressed */
  glLoadIdentity();                 /* in terms of World coordinates */

  glBegin(GL_POLYGON) ;             /* draw a filled polygon */
      glColor3f ( 1.0, 0.3, 0.2);       /* draw in light red */
      glVertex2f( -C/2, -C/2 );         /* (x,y) */
      glVertex2f(  C/2, -C/2 );         /* (x,y) */
      glVertex2f(  C/2,  C/2 );         /* (x,y) */
      glVertex2f( -C/2,  C/2 );         /* (x,y) */
  glEnd();

  glFlush();                        /* send all commands */
}

void main(int argc, char** argv)
{
  glutInit(&argc,argv);
  glutInitWindowSize( A, A );       /* A x A pixel screen window  */

  glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE);
  glutCreateWindow("My Rectangle"); /* window title                   */
  glutDisplayFunc(display);         /* tell OpenGL main loop what     */
  myinit();                         /* set attributes                 */

  glutMainLoop();                   /* pass control to the main loop  */
}


I'm not stick to use this program I just need an OpenGL surface under Dev-C++.
Jun 20, 2013 at 5:18pm
1- main
The main function must return an integer so the proper definition would be:
1
2
3
4
5
int main(int argc, char** argv)
{
    //...
    return 0;
}


2 - Redeclaration of short

line2-In file included from GlTest.cpp
line45-redeclaration of C++ built-in type 'short'


gl/glut.h file from line 2 is probably trying to redeclare short. Open it up and see what's going on on line 45.
Jun 21, 2013 at 11:16am
The 45. line of glut.h:
 
typedef unsigned short wchar_t;
Jun 21, 2013 at 11:17am
Oh, I delete the line, and it is works. At least the test program. Thanks!
Jun 21, 2013 at 2:08pm
Again I must point out that this is an extremely old and outdated version of OpenGL. The functions you're using for rendering have been deprecated in OpenGL for years... and the Glut support lib has not been updated in like 10 years.

I highly recommend at least switching to FreeGlut (the more modern version of the same kind of lib) and using a more modern version of OpenGL.

A good tutorial to get you started is here:

http://www.arcsynthesis.org/gltut/
Jun 21, 2013 at 2:33pm
@Disch, Glad you said it. I thought about mentioning that. :-)

@OP, one OpenGL tip I can't recommend enough; look at shaders soon rather than later. Fixed-function pipelines are dated now. You'll do yourself a world of good by writing your own pixel and fragment shaders, no matter how rudimentary they are.
Jun 21, 2013 at 3:27pm
Agreed @ iHutch.

fwiw, the tutorial I linked introduces you to shaders pretty much immediately.
Topic archived. No new replies allowed.