-
January 27th, 2012, 11:26 AM
#1
Errors C2143 and C2106
I am doing some labs from my Uni course and both VC++2008 and VS2010 are throwing the same errors at me.
My uni lecturer assures me that the code functions in all compilers and sent me the completed program source, but for some reason it still throws the errors on compilation. Code listing as follows:
#include<iostream>
#include<gl/glut.h>
bool mouseActive = false;
bool clearScreen = true;
float mouseX, mouseY;
float lastX, lastY;
float width, height, aspect;
void display()
{
if (clearScreen) {
glClear(GL_COLOR_BUFFER_BIT);
clearScreen = false;
}
// Removed due to keyboard colour commands...
// glColor3f(1.0, 0.0, 0.0);
// glLineWidth(2.0);
glBegin(GL_LINES);
glVertex2f(lastX, lastY);
glVertex2f(mouseX, mouseY);
lastX = mouseX;
lastY = mouseY;
glEnd();
glFlush();
}
void mouse(int button, int state, int x, int y)
{
if(!state){ // Are there any buttons down?
switch(button){ // Which button?
case GLUT_LEFT_BUTTON: // Left: start a scribble
lastX = x;
lastY = y;
mouseActive=true;
break;
case GLUT_RIGHT_BUTTON: // Right: set to clear the screen
clearScreen=true;
glutPostRedisplay();// Schedule a screen update
}
}
else // No buttons pressed.
mouseActive=false;
}
void motion(int x, int y)
{
if(mouseActive) // Any buttons currently down (set in mouse()).
{
mouseX = x; // Update the mouse coordinates.
mouseY = y;
glutPostRedisplay(); // Screen needs updated.
}
}
// Exercise 1. This reshape function does two things...
// 1. Schedules a screen clear to get rid of the graphics
// mess due to buffer memory being reorganized.
// 2. Re-sizes the coordinate system to match the screen
// width and height - calls to viewport etc. necessary
// for this...
void reshape(int x, int y)
{
clearScreen = true;
width = x;
height = y;
glViewport (0, 0, width, height);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D(0, width, height, 0);
}
// Exercises 2 & 3. Key handlers to set background colour
// and line width...
void keyboard(unsigned char key, int x, int y)
{
const unsigned char VK_ESCAPE=0x1b;
switch (key) {
case 'r': // Red
glColor3f(1.0, 0.0, 0.0);
break;
case 'g': // Green
glColor3f(0.0, 1.0, 0.0);
break;
case 'b': // Blue
glColor3f(0.0, 0.0, 1.0);
break;
case 'k': // Black
glColor3f(0.0, 0.0, 0.0);
break;
// Extra statements added to change the background colour...
case 'R': // Red background
glClearColor(1, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
break;
case 'G': // Green background
glClearColor(0, 1, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
break;
case 'B': // Blue background
glClearColor(0, 0, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);
break;
// Extra key handlers for line width...
case '1':
glLineWidth(1);
break;
case '2':
glLineWidth(2);
break;
case '3':
glLineWidth(3);
break;
case '4':
glLineWidth(4);
break;
case '5':
glLineWidth(5);
break;
case '6':
glLineWidth(6);
break;
case VK_ESCAPE: // Quit – the Esc key.
exit(0);
break;
default:
// could do stuff here also
break;
}
}
// Final exercise - the functions below define and implement
// a menu handler.
// handle_menu is called when the right mouse button is clicked.
void handle_menu(int item)
{
switch(item)
{
case 1:
glColor3f(1, 0, 0);
break;
case 2:
glColor3f(0, 1, 0);
break;
case 3:
glColor3f(0, 0, 1);
break;
case 4:
glColor3f(0, 0, 0);
break;
case 5:
glLineWidth(2);
break;
case 6:
glLineWidth(9);
break;
case 7: // Quit.
exit(0);
}
}
// init_menu creates the menu structure and ataches it to
// the right mouse button...
void init_menu()
{
//Create the menu & add items
glutCreateMenu (handle_menu); // Func that will be called
glutAddMenuEntry ("Red", 1);
glutAddMenuEntry ("Green", 2);
glutAddMenuEntry ("Blue", 3);
glutAddMenuEntry ("Black", 4);
glutAddMenuEntry ("Thin", 5);
glutAddMenuEntry ("Thick", 6);
glutAddMenuEntry ("Exit", 7);
//Attach it to the right button
glutAttachMenu (GLUT_RIGHT_BUTTON);
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitWindowSize(500, 500);
glutInitWindowPosition(150, 150);
glutCreateWindow("User-Input");
// Not wanted now there is a reshape() function...
//gluOrtho2D(0, 500, 500, 0); // Note this!!!!!
glClearColor(1.0, 1.0, 1.0, 1.0);
glutMouseFunc(mouse);
glutMotionFunc(motion);
// Needs added (exercise 1b)...
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
// Call to add the menu code...
init_menu();
glutMainLoop();
return 0;
}
The errors appear to be caused by the following line in the keyboard function:
const unsigned char VK_ESCAPE=0x1b;
I am being told that I need a ';' before the constant and that '=':left operand must be I-value.
Can someone steer me in the right direction?
Thanks in advance
-
January 28th, 2012, 06:52 PM
#2
Re: Errors C2143 and C2106
1. Please use code tags when posting code. Your code is practically unreadable.
2. What type of project did you create? If it is anything but a console project, then it's likely that VK_ESCAPE is already defined as a macro. Renaming the variable in your code should do the trick.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|