Thread: map[y][x+1] prob

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    4

    map[y][x+1] prob

    hey,

    i got a problem, i'm trying to create a 2d map from a 2 dimensional array, with x,y and z in it.

    when i add the lines to raise the z he gives a array, i think its somethign in my syntax:

    sy1 = sy - map[y][x];
    ey1 = sy - map[y][x+1];
    sy2 = ey - map[y+1][x];
    ey2 = ey - map[y+1][x+1];

    can someone help me ?

    Code:
    int DrawGLScene(GLvoid){
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	glLoadIdentity();
    
    	GLfloat x, y;
    
    	int maxX = 10;
    	int maxY = 10;
    
    	int mX,mY,sy,ey,sx1,sx2,ex1,ex2,sy1,sy2,ey1,ey2;
    
    	mX = maxX * gridX + maxY * gridX;
    	mY = maxY * gridX;
    
    	for ( y=0; y < maxY; y++ )
    	{
    		sy = y * gridY;
    		ey = sy + gridY;
    
    		for (x=0; x < maxX; x++ )
    		{
    			sx1 = x - ( ( mX - x ) * gridX + ( y * gridX ) );
    			ex1 = sx1 + gridX;
    
    			sx2 = sx1 - gridX;
    			ex2 = ex1 - gridX;
    
    			sy1 = sy - map[y][x];
    			ey1 = sy - map[y][x+1];
    
    			sy2 = ey - map[y+1][x];
    			ey2 = ey - map[y+1][x+1];
    
    			glColor3f(1.0,0.5f,1.0f);	
    
    			glBegin(GL_QUADS);
    				glVertex3f( sx1, sy1, 0.0f);
    				glVertex3f( ex1, ey1, 0.0f);
    				glVertex3f( ex2, ey2, 0.0f);
    				glVertex3f( sx2, sy2, 0.0f);
    			glEnd();
    
    			glLoadIdentity();
    		}
    	}	
    
    	return TRUE;										// Keep Going
    }
    compiling:
    Code:
    C:\Documents and Settings\Maurad3r\Bureaublad\Lesson04\lesson4.cpp(101) : error C2108: subscript is not of integral type
    C:\Documents and Settings\Maurad3r\Bureaublad\Lesson04\lesson4.cpp(101) : error C2108: subscript is not of integral type
    C:\Documents and Settings\Maurad3r\Bureaublad\Lesson04\lesson4.cpp(101) : error C2113: pointer can only be subtracted from another pointer
    C:\Documents and Settings\Maurad3r\Bureaublad\Lesson04\lesson4.cpp(102) : error C2108: subscript is not of integral type
    C:\Documents and Settings\Maurad3r\Bureaublad\Lesson04\lesson4.cpp(102) : error C2108: subscript is not of integral type
    C:\Documents and Settings\Maurad3r\Bureaublad\Lesson04\lesson4.cpp(102) : error C2113: pointer can only be subtracted from another pointer
    C:\Documents and Settings\Maurad3r\Bureaublad\Lesson04\lesson4.cpp(104) : error C2108: subscript is not of integral type
    C:\Documents and Settings\Maurad3r\Bureaublad\Lesson04\lesson4.cpp(104) : error C2108: subscript is not of integral type
    C:\Documents and Settings\Maurad3r\Bureaublad\Lesson04\lesson4.cpp(104) : error C2113: pointer can only be subtracted from another pointer
    C:\Documents and Settings\Maurad3r\Bureaublad\Lesson04\lesson4.cpp(105) : error C2108: subscript is not of integral type
    C:\Documents and Settings\Maurad3r\Bureaublad\Lesson04\lesson4.cpp(105) : error C2108: subscript is not of integral type
    C:\Documents and Settings\Maurad3r\Bureaublad\Lesson04\lesson4.cpp(105) : error C2113: pointer can only be subtracted from another pointer

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > error C2108: subscript is not of integral type
    So stop using floats to index arrays
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Deal or No Deal listbox prob
    By kryptkat in forum Windows Programming
    Replies: 5
    Last Post: 03-30-2009, 06:53 PM
  2. Promblem with code
    By watchdogger in forum C Programming
    Replies: 18
    Last Post: 01-31-2009, 06:36 PM
  3. string manipulation problem
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 10-06-2005, 06:13 AM
  4. Need help to understand this STL code.
    By Hulag in forum C++ Programming
    Replies: 3
    Last Post: 04-26-2005, 01:59 PM
  5. IDE prob
    By MicroFiend in forum C++ Programming
    Replies: 1
    Last Post: 03-04-2004, 04:28 PM