Hi
I’m new to this forum and I’m learning C++ and OpenGL. I’m using Windows XP, texteditor, latest GCC and Gnu Make versions. While I’ve got basic knowledge of C++ (or even less), OpenGL is completely new to me.
I’m following this tutorial (http://www.lighthouse3d.com/opengl/glut/index.php?3), which is, by the way, very good.
But I’m puzzled about two things:
- In the tutorial the main function is written as void:
void main(int argc, char **argv) {
But my gcc compiler gives errors here: “‘main’ must return ‘int’” and “return type for ‘main’ changed to ‘int’”.
I then changed the function into int:
int main(int argc, char **argv) {
Why can’t I have void there?
- If I compile my code with that changed line I get zero errors. But when I try to run the compiled .exe file I get a windows error:
The application failed to initialize properly - 0xc0000005
|OK|
When I comment the lines
gluPerspective(45,ratio,1,1000);
and
gluLookAt(0.0,0.0,5.0,
0.0,0.0,-1.0,
0.0f,1.0f,0.0f);
the error doesn’t occur anymore, but the window has bugs while resizing. Is this error a problem with the glu library?
I’m using the following makefile:
# A simple Makefile
# C++ using GNU Make and GCC
# opengl32.lib glut32.lib glu32.lib odbc32.lib odbccp32.lib
myprogram.exe : myfile.cpp
gcc myfile.cpp -Wall -lopengl -lglu -lglut32
this is my code:
/* hallo.c */
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GLUT/glut.h>
using namespace std;
void renderScene(void) {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex3f(-0.5,-0.5,0.0);
glVertex3f(0.5,0.0,0.0);
glVertex3f(0.0,0.5,0.0);
glEnd();
glFlush();
}
void changeSize(int w, int h) {
// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if(h == 0)
h = 1;
float ratio = 1.0* w / h;
// Reset the coordinate system before modifying
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Set the viewport to be the entire window
glViewport(0, 0, w, h);
// Set the correct perspective.
gluPerspective(45,ratio,1,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0,0.0,5.0,
0.0,0.0,-1.0,
0.0f,1.0f,0.0f);
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(320,320);
glutCreateWindow("3D Tech- GLUT Tutorial");
glutDisplayFunc(renderScene);
glutReshapeFunc(changeSize);
glutMainLoop();
}
I’d appreciate any help from you.
Kenji