opengl/glut code sample + errors...need some help

this is a pretty long code example but i just wanted to know if i’m doing something stupid/wrong. I just attempted to modify an example given from a book to include some other things. I get 3 errors:

C:\My Documents\glstuff emp2 ry.cpp(32) : error C2601: ‘mouse’ : local function definitions are illegal
C:\My Documents\glstuff emp2 ry.cpp(47) : error C2601: ‘main’ : local function definitions are illegal
C:\My Documents\glstuff emp2 ry.cpp(60) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

try.exe - 3 error(s), 0 warning(s)

if anyone sees something that really stands out wrong please point it out cuz i’m a real beginner trying to get a feel for this 2d stuff

#include <iostream.h>
#include <gl/glut.h>

static GLint vertices[] = {25, 25, 100, 325, 175, 25, 175, 325, 250, 25, 325, 325, };
static GLfloat colors[] = {1.0, 0.2, 0.2, 0.2, 0.2, 1.0, 0.8, 1.0, 0.2, 0.75, 0.75,
0.75, 0.35, 0.35 ,0.35 ,0.5, 0.5, 0.5,};

void init(void)

glClearColor(1.0, 1.0, 1.0, 1.0);



void display (void){



glColorPointer(3, GL_FLOAT, 0, colors);

glVertexPointer(2, GL_INT, 0, vertices);


glColor3f(1.0, 1.0, 1.0);






void mouse(int button, int state, int x, int y){
switch (button) {


	if (state == GLUT_DOWN)

		glColor3f(0.5, 0.5, 0.5);






int main (int argc, char** argv)


glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

glutInitWindowSize(250, 250);

glutInitWindowPosition(100, 100);






return 0;


thanx for any help

I copied and had to add a } before the line “void mouse(int button, int state, int x, int y){” to compile it. That gives me just a blank window so the program is not finished yet.

It usually helps to close out the current function before trying to start a new function.

yeah yeah…keep ur sarcasm to urself :stuck_out_tongue:

There is a remedy,

Emacs, by far the most powerful editor, does have paranthesis and bracked matching. So when I get stuck with weird code errors that should work (and the compiler spits out just junk messages) I copy/pase my code in emacs and start checking brackeds…emacs also indents your code automatically when u press tab. It also does a lot of syntax checking. For example if you have a few nested if…elses then you might get confused which else belonged to which if, Emacs automatically will tell you which elses match which ifs. Add a powerful built in ftp and shell and there is no match for emacs. You can create your project in VC++/other compiler and then edit your files using Emacs…I believe you can also make VC++ to use emacs as its default editor…

here is the link


Sorry for the sarcasm, but if you’re working with OpenGL, you should have a pretty good grasp of basic C/C++. This was a pretty basic C/C++ problem. The term “local function definition” should have clued you in that a function was being declared inside another function. (Local meaning inside a function.)

Next thing you know, you’ll start posting errors about undeclared variables.

Nah i have a basic grasp of C++. Just didn’t see that bracket missing…i’ve been getting so many GL errors that i’ve started just asking people before i remember that i can mess up the c++ part 2

It is always easy finding errors in other programmers code.

I beilived that everybody had switching Ctrl+J and Return in emacs so that the line get indented and checked when you press return.