Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chrono1081

macrumors G3
Original poster
Jan 26, 2008
8,922
6,640
Isla Nublar
Hi Guys.

I'm new to OpenGL. The only experience I have in it was tweaking code in already written OpenGL code. Now I am learning it on my own.

I bought the OpenGL SuperBible and its nice but I want to learn to set it up and use it without requiring the GLTools framework the book requires. I turned to the Nehe tutorials, and started this one: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=Mac_OS_X

Anyway XCode appears to be set up correctly, here is the code in its entirety. (GLUT and OpenGL frameworks have been added to the project)


Code:
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>

#define kWindowWidth	400
#define kWindowHeight	300

GLvoid InitGL(GLvoid);
GLvoid DrawGLScene(GLvoid);
GLvoid ReSizeGLScene(int Width, int Height);

int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize (kWindowWidth, kWindowHeight);
	glutInitWindowPosition (100, 100);
	glutCreateWindow (argv[0]);
	
	InitGL();
	
	glutDisplayFunc(DrawGLScene);
	glutReshapeFunc(ReSizeGLScene);
	
	glutMainLoop();
	
	return 0;
}

Is this code supposed to work in this form? (The functions have prototypes but no definition which makes me wonder)

Anyway the errors I get are:

/Users/Scott/Documents/OpenGL Test 2/main.cpp:16: error: '<anonymous>' has incomplete type
/Users/Scott/Documents/OpenGL Test 2/main.cpp:16: error: invalid use of 'GLvoid'
/Users/Scott/Documents/OpenGL Test 2/main.cpp:17: error: '<anonymous>' has incomplete type
/Users/Scott/Documents/OpenGL Test 2/main.cpp:17: error: invalid use of 'GLvoid'
/Users/Scott/Documents/OpenGL Test 2/main.cpp: In function 'int main(int, char**)':
/Users/Scott/Documents/OpenGL Test 2/main.cpp:16: error: too few arguments to function 'GLvoid InitGL(<type error>)'
/Users/Scott/Documents/OpenGL Test 2/main.cpp:28: error: at this point in file
/Users/Scott/Documents/OpenGL Test 2/main.cpp:30: error: invalid conversion from 'GLvoid (*)(<type error>)' to 'void (*)()'
/Users/Scott/Documents/OpenGL Test 2/main.cpp:30: error: initializing argument 1 of 'void glutDisplayFunc(void (*)())'


I'm not sure why the program can't find GLvoid. Its a valid data type, I checked for it. I just don't know enough about OpenGL to be able to tell if this is supposed to happen or if a window is to open. Anyone have any ideas?

Basically I am just looking for bare minimum code needed to open a window that I can build the stuff I've been learning off of.
 
The code as presented is incomplete as you've surmised!

Does the following compile:

Code:
/* =============================================================================
 * File -
 * -----------------------------------------------------------------------------
 */

/* =============================================================================
 * -----------------------------------------------------------------------------
 */

#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>


/* =============================================================================
 * -----------------------------------------------------------------------------
 */

#define kWindowWidth	400
#define kWindowHeight	300


/* =============================================================================
 * -----------------------------------------------------------------------------
 */

void DrawGLScene()
{}


/* =============================================================================
 * -----------------------------------------------------------------------------
 */

void ReSizeGLScene(int xWidth, int yHeight)
{}


/* =============================================================================
 * -----------------------------------------------------------------------------
 */

void InitGL()
{}


/* =============================================================================
 * -----------------------------------------------------------------------------
 */

int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	
	glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	
	glutInitWindowSize (kWindowWidth, kWindowHeight);
	glutInitWindowPosition (100, 100);
	glutCreateWindow (argv[0]);
	
	InitGL();
	
	glutDisplayFunc(DrawGLScene);
	glutReshapeFunc(ReSizeGLScene);
	
	glutMainLoop();
	
	return 0;
}
 
Yes it does! Thank you so much again lloyddean :D I promise I won't be so needy once I get started learning OpenGL :p I've never programmed using a 3D API before. I'm used to working in game engines or with SDL.

It seems like the NeHe tutorials are way out of date. I've been searching for the most basic code to open a window and use the knowledge I'm gaining from the OpenGL SuperBible to try and make something. The OpenGL Superbible is nice, but it moves pretty fast and offers no exercises to try.

Thank you again for the help :D
 
Last edited:
I'd really recommend you check out this.

I haven't tried compiling the downloadable Mac code available through the site so if it gives you trouble I have something that works and compiles on the current version of Xcode. But beware I have a habit of reformatting/reorganizing everything during my process of learning (it forces me to visit and understand the code) so it won't be 100% identical to his.

Let me know!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.