?
Solved

undeclared identifier ?

Posted on 2008-11-11
6
Medium Priority
?
1,645 Views
Last Modified: 2013-12-06
Hello,

On the code below i get continually an error 'undeclared identifier' for multiple things, but what it seems strange is that i already have got every identifier declared.

 'ox' : undeclared identifier      
 'num_x' : undeclared identifier
......
......


How can i solve that error ??

Thanks in advance for any help
0
Comment
Question by:perdoname_
6 Comments
 

Author Comment

by:perdoname_
ID: 22929645

#include "display.h"
 
 
SKELETON* gSkel;			/* Holds skeleton data - available to any function */
MOCAP*	  gMo;				/* Hold motion data - available to any function */
int		  gDelay=0;			/* Holds delay information - available to any function */
 
 
//camera
 
static float   camera_yaw = 0.0f;      
static float   camera_pitch = -20.0f;  
static float   camera_distance = 5.0f; 
 
//mouse
 
static int     drag_mouse_r = 0; 
static int     drag_mouse_l = 0;
static int     drag_mouse_m = 0; 
static int     last_mouse_x, last_mouse_y; 
 
 
static int     win_width, win_height;
 
 
/* Entry point from MAIN.C */
void dorender(int argc, char** argv, SKELETON* skel, MOCAP* mo, int delay) {
 
 
	/* Create GLUT window */
   glutInit(&argc, argv);
   glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
   glutInitWindowSize (600, 600);
   glutInitWindowPosition( 0, 0 );
   glutCreateWindow ("Mocap");
 
   /* Setup GLUT callbacks */
   glutReshapeFunc (reshape);
   glutKeyboardFunc (keyboard);
   glutDisplayFunc (display);
   glutMouseFunc( mouse );
   glutMotionFunc( motion );
   glutIdleFunc (idle);
 
   /* Initialise any OpenGL state */
   init();
   initEnvironment();
 
	/* Set global variables */
   gSkel=skel;
   gMo=mo;
   gDelay=delay;
 
   /* Kick off the GLUT main loop */
   glutMainLoop();
   
 
}
 
 
 
void  drawMessage( int line_no, const char * message )
{
	int   i;
	if ( message == NULL )
		return;
 
	glMatrixMode( GL_PROJECTION );
	glPushMatrix();
	glLoadIdentity();
	gluOrtho2D( 0.0, win_width, win_height, 0.0 );
 
	glMatrixMode( GL_MODELVIEW );
	glPushMatrix();
	glLoadIdentity();
 
	
	glDisable( GL_DEPTH_TEST );
	glDisable( GL_LIGHTING );
 
	glColor3f( 1.0, 0.0, 0.0 );
	glRasterPos2i( 8, 24 + 18 * line_no );
	for ( i=0; message[i]!='\0'; i++ )
		glutBitmapCharacter( GLUT_BITMAP_HELVETICA_18, message[i] );
 
 
	glEnable( GL_DEPTH_TEST );
	glEnable( GL_LIGHTING );
	glMatrixMode( GL_PROJECTION );
	glPopMatrix();
	glMatrixMode( GL_MODELVIEW );
	glPopMatrix();
}
 
 
/* Keyboard callback from GLUT */
void keyboard(unsigned char key, int x, int y)
{
 
	/* ESCAPE to exit */
	
 
	switch(key) {
 
			case 0x1b:  
						parser_free_skeleton(gSkel);
						parser_free_mocap(gMo);
						exit(0);
						break;
 
 
	}
 
}
 
 
/* Mouse callback from GLUT */ 
void  mouse( int button, int state, int mx, int my )
{
	
	if ( ( button == GLUT_LEFT_BUTTON ) && ( state == GLUT_DOWN ) )
		drag_mouse_l = 1;
	
	else if ( ( button == GLUT_LEFT_BUTTON ) && ( state == GLUT_UP ) )
		drag_mouse_l = 0;
 
	
	if ( ( button == GLUT_RIGHT_BUTTON ) && ( state == GLUT_DOWN ) )
		drag_mouse_r = 1;
	
	else if ( ( button == GLUT_RIGHT_BUTTON ) && ( state == GLUT_UP ) )
		drag_mouse_r = 0;
 
	
	if ( ( button == GLUT_MIDDLE_BUTTON ) && ( state == GLUT_DOWN ) )
		drag_mouse_m = 1;
	
	else if ( ( button == GLUT_MIDDLE_BUTTON ) && ( state == GLUT_UP ) )
		drag_mouse_m = 0;
 
	
	glutPostRedisplay();
 
	
	last_mouse_x = mx;
	last_mouse_y = my;
}
 
 
void  motion( int mx, int my )
{
	if ( drag_mouse_r )
	{
		camera_yaw -= ( mx - last_mouse_x ) * 1.0;
		if ( camera_yaw < 0.0 )
			camera_yaw += 360.0;
		else if ( camera_yaw > 360.0 )
			camera_yaw -= 360.0;
 
		camera_pitch -= ( my - last_mouse_y ) * 1.0;
		if ( camera_pitch < -90.0 )
			camera_pitch = -90.0;
		else if ( camera_pitch > 90.0 )
			camera_pitch = 90.0;
	}
	
	if ( drag_mouse_l )
	{
		
		camera_distance += ( my - last_mouse_y ) * 0.2;
		if ( camera_distance < 2.0 )
			camera_distance = 2.0;
	}
 
	
	last_mouse_x = mx;
	last_mouse_y = my;
 
	glutPostRedisplay();
}
 
 
/* Called back when GLUT idling */
void idle() {
 
}
 
/* Called back by GLUT when the window is resized */
void reshape(int w, int h)
{
 
   glViewport(0, 0, w, h);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   
   gluPerspective(60,(GLfloat)w/(GLfloat)h,0.01,100.0);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
 
   win_width = w;
   win_height = h;
 
}
 
/* Called by us in dorender() to init any OpenGL state */
void init(void)
{  
 
   glClearColor (0.0, 0.0, 0.0, 0.0);
 
}
 
 
 
void  initEnvironment( void )
{
 
	float  light0_position[] = { 10.0, 10.0, 10.0, 1.0 };
	float  light0_diffuse[] = { 0.8, 0.8, 0.8, 1.0 };
	float  light0_specular[] = { 1.0, 1.0, 1.0, 1.0 };
	float  light0_ambient[] = { 0.1, 0.1, 0.1, 1.0 };
	glLightfv( GL_LIGHT0, GL_POSITION, light0_position );
	glLightfv( GL_LIGHT0, GL_DIFFUSE, light0_diffuse );
	glLightfv( GL_LIGHT0, GL_SPECULAR, light0_specular );
	glLightfv( GL_LIGHT0, GL_AMBIENT, light0_ambient );
	glEnable( GL_LIGHT0 );
 
	
	glEnable( GL_LIGHTING );
 
	
	glEnable( GL_COLOR_MATERIAL );
 
	
	glEnable( GL_DEPTH_TEST );
 
	
	glCullFace( GL_BACK );
	glEnable( GL_CULL_FACE );
 
	glClearColor( 0.5, 0.5, 0.8, 0.0 );
 
}
 
 
 
 
 
/* Called when GLUT wants to repaint the screen */
void  display( void )
{
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
 
    glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();
	glTranslatef( 0.0, 0.0, - camera_distance );
	glRotatef( - camera_pitch, 1.0, 0.0, 0.0 );
	glRotatef( - camera_yaw, 0.0, 1.0, 0.0 );
	glTranslatef( 0.0, -0.5, 0.0 );
 
	float  light0_position[] = { 10.0, 10.0, 10.0, 1.0 };
	glLightfv( GL_LIGHT0, GL_POSITION, light0_position );
 
	
	float  size = 1.5f;
	int  num_x = 10, num_z = 10;
	double  ox, oz;
	glBegin( GL_QUADS );
		glNormal3d( 0.0, 1.0, 0.0 );
		ox = -(num_x * size) / 2;
		for ( int x=0; x<num_x; x++, ox+=size )
		{
			oz = -(num_z * size) / 2;
			for ( int z=0; z<num_z; z++, oz+=size )
			{
				if ( ((x + z) % 2) == 0 )
					glColor3f( 1.0, 1.0, 1.0 );
				else
					glColor3f( 0.8, 0.8, 0.8 );
				glVertex3d( ox, 0.0, oz );
				glVertex3d( ox, 0.0, oz+size );
				glVertex3d( ox+size, 0.0, oz+size );
				glVertex3d( ox+size, 0.0, oz );
			}
		}
	glEnd();
   /**********
	*	glColor3f( 1.0f, 0.0f, 0.0f );
	*	if ( asf )
	*		asf->RenderFigure( frame_no, 0.02f );
	*
	*	
	*	char  message[ 64 ];
	*	if ( asf )
	*		sprintf( message, "%.2f (%d)", animation_time, frame_no );
	*	else
	*		sprintf( message, "Press 'L' key to Load ASF/AMC file" );
	*	drawMessage( 0, message );
	*
	*********/
	
    glutSwapBuffers();
}
 
 
 
 
 
 
 
 
 
//header :
 
#ifndef MOCAP_DISPLAY_INCLUDED
#define MOCAP_DISPLAY_INCLUDED
 
 
#ifdef WIN32
	#include "windows.h"
	#define strcasecmp stricmp
#endif
 
#include "GL/gl.h"
#include "GL/glut.h"
 
#include <math.h>
 
#include "parser.h"
 
void dorender(int argc, char** argv, SKELETON* skel, MOCAP* mo, int delay);
 
/* GLUT callbacks */
void keyboard(unsigned char key, int x, int y);
void reshape(int w, int h);
void init(void);
void initEnvironment(void);
void display(void);
void idle(void);
void mouse(int button, int state, int mx, int my );
void motion(int mx, int my);
 
#endif

Open in new window

0
 
LVL 20

Expert Comment

by:ikework
ID: 22929678
hey perdoname_

can you post the real compiler-error here as well as the line-number it refers to?

ike
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 22929705
If you are compiling this as a C program, then C requires all declarations to be at the beginning of a code block which is not the case here
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:perdoname_
ID: 22929719
ok is in the code snippet

thanks
Error	2	error C2065: 'light0_position' : undeclared identifier		262
Error	9	error C2065: 'num_x' : undeclared identifier		270	
Error	16	error C2065: 'num_x' : undeclared identifier		271	
Error	24	error C2065: 'num_z' : undeclared identifier		273	
Error	31	error C2065: 'num_z' : undeclared identifier		274	
Error	8	error C2065: 'ox' : undeclared identifier		270	
Error	19	error C2065: 'ox' : undeclared identifier		271	
Error	40	error C2065: 'ox' : undeclared identifier		280	
Error	42	error C2065: 'ox' : undeclared identifier		281	
Error	45	error C2065: 'ox' : undeclared identifier		282	
Error	49	error C2065: 'ox' : undeclared identifier		283	
Error	23	error C2065: 'oz' : undeclared identifier		273	
Error	34	error C2065: 'oz' : undeclared identifier		274	
Error	41	error C2065: 'oz' : undeclared identifier		280	
Error	43	error C2065: 'oz' : undeclared identifier		281	
Error	47	error C2065: 'oz' : undeclared identifier		282	
Error	51	error C2065: 'oz' : undeclared identifier		283	
Error	10	error C2065: 'size' : undeclared identifier		270	
Error	21	error C2065: 'size' : undeclared identifier		272	
Error	25	error C2065: 'size' : undeclared identifier		273	
Error	36	error C2065: 'size' : undeclared identifier		275	
Error	44	error C2065: 'size' : undeclared identifier		281	
Error	46	error C2065: 'size' : undeclared identifier		282	
Error	48	error C2065: 'size' : undeclared identifier		282	
Error	50	error C2065: 'size' : undeclared identifier		283	
Error	15	error C2065: 'x' : undeclared identifier		271	
Error	18	error C2065: 'x' : undeclared identifier		271	
Error	38	error C2065: 'x' : undeclared identifier		276	
Error	30	error C2065: 'z' : undeclared identifier		274	
Error	33	error C2065: 'z' : undeclared identifier		274	
Error	39	error C2065: 'z' : undeclared identifier		276	

Open in new window

0
 
LVL 11

Accepted Solution

by:
jgordos earned 2000 total points
ID: 22931124
C, unlike modern languages, does not allow you to declare things the way you did.

You have the following (I'll cut out some stuff so you can see it... )

void  display( void )
{
      glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
             
                 /* MORE CODE HERE */
 
      float  light0_position[] = { 10.0, 10.0, 10.0, 1.0 };                     <---- THIS IS WRONG
      glLightfv( GL_LIGHT0, GL_POSITION, light0_position );
 
      
      float  size = 1.5f;                                                                          <---- THIS IS WRONG

      int  num_x = 10, num_z = 10;                                                        <---- THIS IS WRONG


You need to move all your declarations up to the top of the routine.

-john

0
 

Author Closing Comment

by:perdoname_
ID: 31515479
can you please check that question as well?
http://www.experts-exchange.com/Programming/Languages/C/Q_23895549.html

thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question