C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-08-2003, 06:44 PM   #1
left crog... back when?
 
incognito's Avatar
 
Join Date: Oct 2001
Posts: 1,427
Didn't quite know where to post this.......compiler problem...

I know this code is correct but it's not compiling....I know it's a problem with the "includes" or something, but I don't know what it is.


Code:
/****************************************************************************
 chapter1.cpp
 
 A simple OpenGL/GLUT demonstration showing a texture mapped, lit, spinning
 cube reflecting in a surface.
  
 This demo should give you a general idea of what GLUT is.  For more
 information, visit the official GLUT page at:
 
       http://reality.sgi.com/opengl/glut3/glut3.html
 
 Author   :   Dave Astle
 Date     :   8/23/2000

 Written for OpenGL Game Programming
*****************************************************************************/

/********************************* Includes *********************************/
#include <gl\glaux.h>
#include <gl\glut.h>
#include <iostream.h>
#include "HiResTimer.h"


/*************************** Macros and constants ***************************/
enum rendermode_t {
  RENDER_REFLECTED,
  RENDER_SHADOW,
  RENDER_NORMAL
};

const GLfloat DEGREES_PER_SECOND = 60.0f;


/******************************** Prototypes ********************************/
void Initialize();
void MouseHandler(int button, int state, int x, int y);
void KeyboardHandler(unsigned char key, int x, int y);
void MainMenuHandler(int option);
void Animate();
void Reshape(int width, int height);
void Display();

void LoadTexture(char *filename, GLuint &texture);
void DrawScene(rendermode_t mode);
void DrawCube();
void DrawSurface();


/********************************* Globals **********************************/
// index for the texture we'll load for the cube
GLuint g_cubeTexture;

// how much to rotate the cube around an axis
GLfloat g_rotationAngle = 0.0;

CHiResTimer g_timer;


/****************************************************************************
 main()

 Setup GLUT and OpenGL, drop into the event loop
*****************************************************************************/
int main(int argc, char **argv)
{
  // Setup the basic GLUT stuff
  glutInit (&argc, argv);
  glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL);

  // Create the window
  glutInitWindowSize(512, 512);
  glutInitWindowPosition(400, 350);
  glutCreateWindow("Chapter 1");

  Initialize();

  // Register the event callback functions
  glutDisplayFunc(Display); 
  glutReshapeFunc(Reshape);
  glutMouseFunc(MouseHandler);
  glutKeyboardFunc(KeyboardHandler);
  glutIdleFunc(Animate);

  // At this point, control is relinquished to the GLUT event handler.
  // Control is returned as events occur, via the callback functions.
  glutMainLoop();   
   
  return 0;
} // end main()


/****************************************************************************
 Initialize()

 One time setup, including creating menus, creating a light, setting the
 shading mode and clear color, and loading textures.
*****************************************************************************/
void Initialize()
{
  // set up the only meny
  int mainMenu;

  mainMenu = glutCreateMenu(MainMenuHandler);

  glutSetMenu(mainMenu);
  glutAddMenuEntry("Exit", 0);
  glutAttachMenu(GLUT_RIGHT_BUTTON);

  g_timer.Init();

  // set the background color
  glClearColor(0.0, 0.0, 0.0, 0.0);

  // set the shading model
  glShadeModel(GL_SMOOTH);

  // set up a single white light
  GLfloat lightColor[] = { 1.0f, 1.0f, 1.0f, 1.0 };

  glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);
  glLightfv(GL_LIGHT0, GL_SPECULAR, lightColor);

  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  glEnable(GL_DEPTH_TEST);

  // load the texture for the cube
  LoadTexture("opengl.bmp", g_cubeTexture);

  // make the modelview matrix active, and initialize it
  glMatrixMode(GL_MODELVIEW);
} // end Initialize()


/****************************************************************************
 MouseHandler()
 
 Handle mouse events. For this simple demo, just exit on a left click.
*****************************************************************************/
void MouseHandler(int button, int state, int x, int y)
{
  switch (button)
  {
  case GLUT_LEFT_BUTTON:
    {
      exit(0);
    } break;
  default:
    break;
  }

  // force a screen redraw
  glutPostRedisplay();
} // end MouseHandler()


/****************************************************************************
 KeyboardHandler()

 Keyboard handler. Again, we'll just exit when q is pressed.
*****************************************************************************/
void KeyboardHandler(unsigned char key, int x, int y)
{
  switch (key)
  {
  case 'q':  // exit
    {
      exit(0);
    } break;
  default:
    {
    } break;
  }
  glutPostRedisplay();
} // end KeyboardHandler()


/****************************************************************************
 MainMenuHandler()

 Main menu callback.
*****************************************************************************/
void MainMenuHandler(int option)
{
  switch(option)
  {
  case 0:
    {
      exit(0);
    } break;
  default:
    break;
  }
  glutPostRedisplay();
} // end MainMenuHandler()


/****************************************************************************
 Animate()

 Rotate the cube by 4 degrees and force a redisplay.
*****************************************************************************/
void Animate()
{
  glutPostRedisplay();
} // end Animate()


/****************************************************************************
 Reshape()

 Reset the viewport for window changes
*****************************************************************************/
void Reshape(int width, int height)
{
  if (height == 0)
    return;
  glViewport(0, 0, (GLsizei) width, (GLsizei) height);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(90.0, width/height, 1.0, 100.0);

  glMatrixMode(GL_MODELVIEW);
} // end Reshape


/****************************************************************************
 Display()

 Clear and redraw the scene.
*****************************************************************************/
void Display()
{
  g_rotationAngle += (DEGREES_PER_SECOND * g_timer.GetElapsedSeconds());

  static int s_frames = 0;

  if (++s_frames > 100)
  {
    cout << g_timer.GetFPS(100) << endl;
    s_frames = 0;
  }

  // set up the view orientation looking at the origin from slightly above
  // and to the left
  glLoadIdentity();
  gluLookAt(0.0, 1.0, 6.0,
            0.0, 0.0, 0.0,
            0.0, 1.0, 0.0);

  // clear the screen
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glRotatef(-g_rotationAngle/8.0, 0.0, 1.0, 0.0);

  // draw the reflected cube first, with fog enable for a more realistic
  // effect
  glEnable(GL_FOG);
  glFogf(GL_FOG_END, 5.0);
  glFogf(GL_FOG_DENSITY, 0.4);
  DrawScene(RENDER_REFLECTED);
  glDisable(GL_FOG);

  // now draw the scene with the shadow
  DrawScene(RENDER_SHADOW);

  // now draw the real cube
  DrawScene(RENDER_NORMAL);

  // draw everything and swap the display buffer
  glFlush();
  glutSwapBuffers();
} // end Display()


/****************************************************************************
 LoadTexture()

 Loads the texture from the specified file and stores it in iTexture. Note
 that we're using the GLAUX library here, which is generally discouraged,
 but in this case spares us having to write a bitmap loading routine.
*****************************************************************************/
void LoadTexture(char *filename, GLuint &texture)
{
  AUX_RGBImageRec *image[1];
  memset(image, 0, sizeof(void *));

  // if the file can be read, load the texture
  if (image[0] = auxDIBImageLoad(filename))
  {
    glGenTextures(1, &texture);
    glBindTexture(GL_TEXTURE_2D, texture);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, 3, image[0]->sizeX, image[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image[0]->data);
  }

/**** Edited out some of the program to not make this page too bulkly******/

/****************************************************************************
 DrawSurface()

 Draws a simple plane to provide a reflection surface.
*****************************************************************************/
void DrawSurface()
{
  // make sure the light is positioned correctly
  GLfloat lightPos[4] = {3.0, 3.0, 3.0, 1.0};
  glLightfv(GL_LIGHT0, GL_POSITION, lightPos);

  // set up the surface's color
  GLfloat surfaceColor[] = { 0.2f, 0.4f, 0.2f, 0.5 };
  glMaterialfv(GL_FRONT, GL_SPECULAR, surfaceColor);
  glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, surfaceColor);
  glMaterialf(GL_FRONT, GL_SHININESS, 200.0);

  // set up blending so we can see the reflected cube through the
  // surface, and thus create the illusion of reflection
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  glBegin(GL_QUADS);
  glNormal3f(0.0, 1.0, 0.0);

  // to have lighting effects show up at all, we need to draw the
  // surface as a lot of quads, not just one
  GLfloat x = -5.0, z = -5.0;

  for (GLint i = 0; i < 10; i++, x += 1)
  {
    for (GLint j = 0; j < 10; j++, z += 1)
    {
      // draw the plane slightly offset so the shadow shows up
      glVertex3f(x, -0.1, z);
      glVertex3f(x + 1.0, -0.1, z);
      glVertex3f(x + 1.0, -0.1, z + 1.0);
      glVertex3f(x, -0.1, z + 1.0);
    }
    z = -5.0;
  }

  glEnd();

  glDisable(GL_BLEND);
} // end DrawSurface()
Here is the Compiler log

Code:
Compiler: Default compiler
Building Makefile: "C:\Documents and Settings\Incognito\Desktop\chapter1\Makefile.win"
Executing  make...
make.exe -f "C:\Documents and Settings\Incognito\Desktop\chapter1\Makefile.win" all
g++.exe -c chapter1.cpp -o chapter1.o -I"C:/Dev-Cpp/include/c++"  -I"C:/Dev-Cpp/include" -D__GNUWIN32__ -W -DWIN32 -DNDEBUG -D_CONSOLE -D_MBCS  -ansi -traditional-cpp

chapter1.cpp:20:21: gl\glut.h: No such file or directory
In file included from chapter1.cpp:21:
C:/Dev-Cpp/include/iostream.h:52:47: ios.h: No such file or directory
C:/Dev-Cpp/include/iostream.h:54:53: streamb.h: No such file or directory
C:/Dev-Cpp/include/iostream.h:56:51: istream.h: No such file or directory
C:/Dev-Cpp/include/iostream.h:58:51: ostream.h: No such file or directory
In file included from chapter1.cpp:21:
C:/Dev-Cpp/include/iostream.h:66: parse error before `,' token
C:/Dev-Cpp/include/iostream.h:69: destructors must be member functions
C:/Dev-Cpp/include/iostream.h:69: virtual outside class declaration
C:/Dev-Cpp/include/iostream.h:70: parse error before `protected'
C:/Dev-Cpp/include/iostream.h:72: parse error before `&' token
C:/Dev-Cpp/include/iostream.h:72: ISO C++ forbids declaration of `iostream' 
   with no type

C:/Dev-Cpp/include/iostream.h:73: syntax error before `&' token
C:/Dev-Cpp/include/iostream.h:74: syntax error before `&' token
C:/Dev-Cpp/include/iostream.h:77: `istream' was not declared in this scope
C:/Dev-Cpp/include/iostream.h:77: parse error before `)' token
C:/Dev-Cpp/include/iostream.h:77: ISO C++ forbids declaration of `iostream' 
   with no type
C:/Dev-Cpp/include/iostream.h:78: `ostream' was not declared in this scope
C:/Dev-Cpp/include/iostream.h:78: parse error before `)' token
C:/Dev-Cpp/include/iostream.h:78: ISO C++ forbids declaration of `iostream' 
   with no type
C:/Dev-Cpp/include/iostream.h:81: syntax error before `&' token
C:/Dev-Cpp/include/iostream.h:81: syntax error before `::' token
C:/Dev-Cpp/include/iostream.h:83: syntax error before `&' token
C:/Dev-Cpp/include/iostream.h:88: parse error before `&' token

chapter1.cpp: In function `int main(int, char**)':
chapter1.cpp:68: `glutInit' undeclared (first use this function)
chapter1.cpp:68: (Each undeclared identifier is reported only once for each 
   function it appears in.)
chapter1.cpp:69: `GLUT_DOUBLE' undeclared (first use this function)
chapter1.cpp:69: `GLUT_RGB' undeclared (first use this function)
chapter1.cpp:69: `GLUT_DEPTH' undeclared (first use this function)
chapter1.cpp:69: `GLUT_STENCIL' undeclared (first use this function)
chapter1.cpp:69: `glutInitDisplayMode' undeclared (first use this function)
chapter1.cpp:72: `glutInitWindowSize' undeclared (first use this function)
chapter1.cpp:73: `glutInitWindowPosition' undeclared (first use this function)
chapter1.cpp:74: `glutCreateWindow' undeclared (first use this function)
chapter1.cpp:79: `glutDisplayFunc' undeclared (first use this function)
chapter1.cpp:80: `glutReshapeFunc' undeclared (first use this function)
chapter1.cpp:81: `glutMouseFunc' undeclared (first use this function)
chapter1.cpp:82: `glutKeyboardFunc' undeclared (first use this function)
chapter1.cpp:83: `glutIdleFunc' undeclared (first use this function)
chapter1.cpp:87: `glutMainLoop' undeclared (first use this function)

chapter1.cpp: In function `void Initialize()':

chapter1.cpp:104: `glutCreateMenu' undeclared (first use this function)
chapter1.cpp:106: `glutSetMenu' undeclared (first use this function)
chapter1.cpp:107: `glutAddMenuEntry' undeclared (first use this function)
chapter1.cpp:108: `GLUT_RIGHT_BUTTON' undeclared (first use this function)
chapter1.cpp:108: `glutAttachMenu' undeclared (first use this function)

chapter1.cpp: In function `void MouseHandler(int, int, int, int)':
chapter1.cpp:145: `GLUT_LEFT_BUTTON' undeclared (first use this function)
chapter1.cpp:154: `glutPostRedisplay' undeclared (first use this function)

chapter1.cpp: In function `void Display()':
chapter1.cpp:241: `cout' undeclared (first use this function)
chapter1.cpp:241: `endl' undeclared (first use this function)
chapter1.cpp:273: `glutSwapBuffers' undeclared (first use this function)

make.exe: *** [chapter1.o] Error 1

Execution terminated

But look at how the directories are set up...........


So don't know what the problem might be.......help please.......
Attached Images
 
__________________
There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

"...The only real game I thank in the world is baseball..." --Babe Ruth

"Life is beautiful"-Don Corleone right before he died.

"The expert on anything was once a beginner" -Baseball poster I own.


Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

Last edited by incognito; 02-08-2003 at 07:00 PM.
incognito is offline   Reply With Quote
Old 02-08-2003, 06:52 PM   #2
Registered User
 
Join Date: Sep 2002
Posts: 1,640
That's ugly, You seem to have a seriously messed up include
directory, Tried reinstalling?
Travis Dane is offline   Reply With Quote
Old 02-08-2003, 06:52 PM   #3
Crazy Fool
 
Perspective's Avatar
 
Join Date: Jan 2003
Location: Canada
Posts: 2,588
do you have the glut32.dll in your windoze system folder as well?
Perspective is offline   Reply With Quote
Old 02-08-2003, 06:53 PM   #4
left crog... back when?
 
incognito's Avatar
 
Join Date: Oct 2001
Posts: 1,427
Ok changed this



/*

#include <glaux.h>
#include <glut.h>
#include <iostream.h>
#include "HiResTimer.h"

*/

And now I only get these errors.


/*

Compiler: Default compiler
Building Makefile: "C:\Documents and Settings\Incognito\Desktop\chapter1\Makefile.win"
Executing make...
make.exe -f "C:\Documents and Settings\Incognito\Desktop\chapter1\Makefile.win" all
g++.exe -c chapter1.cpp -o chapter1.o -I"C:/Dev-Cpp/include/c++" -I"C:/Dev-Cpp/include" -D__GNUWIN32__ -W -DWIN32 -DNDEBUG -D_CONSOLE -D_MBCS -ansi -traditional-cpp

In file included from chapter1.cpp:21:
C:/Dev-Cpp/include/iostream.h:52:47: ios.h: No such file or directory
C:/Dev-Cpp/include/iostream.h:54:53: streamb.h: No such file or directory
C:/Dev-Cpp/include/iostream.h:56:51: istream.h: No such file or directory
C:/Dev-Cpp/include/iostream.h:58:51: ostream.h: No such file or directory

In file included from chapter1.cpp:21:
C:/Dev-Cpp/include/iostream.h:66: parse error before `,' token
C:/Dev-Cpp/include/iostream.h:69: destructors must be member functions

C:/Dev-Cpp/include/iostream.h:69: virtual outside class declaration
C:/Dev-Cpp/include/iostream.h:70: parse error before `protected'
C:/Dev-Cpp/include/iostream.h:72: parse error before `&' token
C:/Dev-Cpp/include/iostream.h:72: ISO C++ forbids declaration of `iostream'
with no type
C:/Dev-Cpp/include/iostream.h:73: syntax error before `&' token
C:/Dev-Cpp/include/iostream.h:74: syntax error before `&' token
C:/Dev-Cpp/include/iostream.h:77: `istream' was not declared in this scope
C:/Dev-Cpp/include/iostream.h:77: parse error before `)' token
C:/Dev-Cpp/include/iostream.h:77: ISO C++ forbids declaration of `iostream'
with no type
C:/Dev-Cpp/include/iostream.h:78: `ostream' was not declared in this scope
C:/Dev-Cpp/include/iostream.h:78: parse error before `)' token
C:/Dev-Cpp/include/iostream.h:78: ISO C++ forbids declaration of `iostream'
with no type
C:/Dev-Cpp/include/iostream.h:81: syntax error before `&' token
C:/Dev-Cpp/include/iostream.h:81: syntax error before `::' token
C:/Dev-Cpp/include/iostream.h:83: syntax error before `&' token
C:/Dev-Cpp/include/iostream.h:88: parse error before `&' token

chapter1.cpp: In function `void Display()':
chapter1.cpp:241: `cout' undeclared (first use this function)
chapter1.cpp:241: (Each undeclared identifier is reported only once for each
function it appears in.)
chapter1.cpp:241: `endl' undeclared (first use this function)

make.exe: *** [chapter1.o] Error 1

Execution terminated

*/
__________________
There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

"...The only real game I thank in the world is baseball..." --Babe Ruth

"Life is beautiful"-Don Corleone right before he died.

"The expert on anything was once a beginner" -Baseball poster I own.


Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.
incognito is offline   Reply With Quote
Old 02-08-2003, 06:54 PM   #5
left crog... back when?
 
incognito's Avatar
 
Join Date: Oct 2001
Posts: 1,427
Quote:
Originally posted by Perspective
do you have the glut32.dll in your windoze system folder as well?

Yes I do now it seems to have a problem with <iostream>
__________________
There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

"...The only real game I thank in the world is baseball..." --Babe Ruth

"Life is beautiful"-Don Corleone right before he died.

"The expert on anything was once a beginner" -Baseball poster I own.


Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.
incognito is offline   Reply With Quote
Old 02-08-2003, 07:42 PM   #6
left crog... back when?
 
incognito's Avatar
 
Join Date: Oct 2001
Posts: 1,427
Got it to work thanks.
__________________
There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

"...The only real game I thank in the world is baseball..." --Babe Ruth

"Life is beautiful"-Don Corleone right before he died.

"The expert on anything was once a beginner" -Baseball poster I own.


Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.
incognito is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Any 1 can write a C cording for this problem plz post hear.. cbuwa C Programming 6 08-21-2007 01:48 PM
A question related to strcmp meili100 C++ Programming 6 07-07-2007 02:51 PM
compiler problem sofarsoclose C Programming 3 07-10-2003 11:39 AM
problem solving compiler errors Jan79 C++ Programming 1 07-02-2003 10:59 AM
Comile problem using latest Dev C++ Compiler shiny_dico_ball C++ Programming 6 06-06-2003 05:32 PM


All times are GMT -6. The time now is 08:17 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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