Jump to content
  • Advertisement
Sign in to follow this  
Random89

OpenGL Creating map using arrays

This topic is 3344 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Basically I am trying to make a maze in OpenGL. The problem I am having is that I am using array lists for the maze map but it doesn't create the shape I want. The code is below:
float wallX[13] = {25, 15, 35, 55, 45, 45, 65, 15, 65, 55, 45, 35, 25}; //Array for columns
float wallY[26] = {10, 25, 15, 45, 15, 35, 15, 45, 15, 25, 35, 55, 35, 45, 55, 75, 55, 75, 65, 75, 65, 85, 75, 85, 95, 105}; //Array for what part of the columns are coloured, each pair is a line
float pi = 0;
int WallXCo = 0;
int WallYCo = 0;
float WallXCo1;
float WallXCo2;
float WallYCo1;
float WallYCo2;
for(pi = 0; pi < 13; pi++)
{
	WallXCo1 = wallX[WallXCo] - 1.25;
	WallXCo2 = wallX[WallXCo] + 1.25;
	WallYCo1 = (wallY[WallYCo] - 1.25) * -1;
	WallYCo2 = (wallY[WallYCo + 1] + 1.25)*-1;
	drawWall(WallXCo1, WallYCo1, WallXCo2, WallYCo2);
	WallXCo = WallXCo + 1;
	WallYCo = WallYCo + 2;
}
 void drawWall(float WallXCo1, float WallYCo1, float WallYCo2, float WallXCo2)
{
	glColor3f(1,0,1);
	glBegin(GL_POLYGON);
	glVertex2f((WallXCo1),(WallYCo1));
	glVertex2f((WallXCo2),(WallYCo1));
	glVertex2f((WallXCo2),(WallYCo2));
	glVertex2f((WallXCo1),(WallYCo2));
	glEnd();
}
This is just the code for the vertical sections of the map. Each X coordinate has two Y coordinates (WallX[0] equates to wallY[0] and wallY[1] making a line 5 in width between the two points). However instead of any sort of map coming out of it I just get a mass of green with no shape. Anyone know what I am doing wrong? ryvpkf0r.jpg That is what is rendered. Also I have run the above code using Cout and all the coordinates given are correct.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!