Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

MarauderIIC

Image is rotated. I didn't tell it to :P

This topic is 5138 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

Alright. I'm storing a custom file format representing an image in a 32x32 format, which I then load into a vector of vectors.
vector < vector <unsigned int> > land;
// has contents of:

//(row# : contents)

 0: 99999999999999999999999999999999
 1: 90000000000000000000000000000099
 2: 90000000000000000000000000000099
 3: 91111111111111111111111111111199
 4: 90000000000000000000000000000099
 5: 90000000000000000000000000000099
 6: 90000000000000000000000000000099
 7: 90000000000000000000000000000099
 8: 90000000000000000000000002000099
 9: 90000000000000000000000022200099
10: 90000000000000000000000222220099
11: 90000001111111111111110000000099
12: 90000000000000000000000100000099
13: 90001111111111111111100100000099
14: 90000000000000000000000100000099
15: 90000000000000000000000000010099
16: 90000000000000000022222211122299
17: 90000000000000000100000000000099
18: 90000000000000000100000000000099
19: 90000000000000000000000000000099
20: 90000111111111111111122222111199
21: 90001222222200000000000000000099
22: 90010000000000000000000000000099
23: 90100000000000000000000000000099
24: 91000000000000000000000000000099
25: 90022211122222222222000000000099
26: 90000266622777200000000000000099
27: 90000222222222200000000000000099
28: 90000000000000000000002222220099
29: 90000000000000000000000000000099
30: 90000000000000000000000000000099
31: 99999999999999999998888888889999
 
I have it like that instead of a 2d array so I can eventually make it more flexible. Anyway. I then, of course, have to load it into a 3d array so I can make it into a texture. This is absurdly inefficient, the way I did it, but that's beside the point.
void World::generateTerrain() {

	debug("generateTerrain() : Generating...");

	if (landGen)
		delete landGen;

	if (!(landGen = new Texture)) {
		debug("generateTerrain() : Out of memory.");
		exit(3);
	}

	GLfloat pixelData[32][32][3];
	unsigned int r, g, b;

	int width = atoi(text["W"].c_str());
	int height = land.size();

	for (unsigned int h = 0;h < height;h++) {
		for (unsigned int w = 0;w < land.at(h).size();w++) {
			if (land.at(h).at(w) == 0)
				continue;

			switch(land.at(h).at(w)) {
			case 1:
				r = 165;
				g = 105;
				b = 25;
				break;
			case 2:
				r = 150;
				g = 150;
				b = 150;
				break;
			case 6:
				r = 180;
				g = 90;
				b = 90;
				break;
			case 7:
				r = 250;
				g = 130;
				b = 60;
				break;
			case 8:
				r = 35;
				g = 115;
				b = 190;
				break;
			case 9:
				r = 255;
				g = 0;
				b = 255;
				break;
			}		
			pixelData[w][h][0] = (GLfloat)r/(GLfloat)255.0f;
			pixelData[w][h][1] = (GLfloat)g/(GLfloat)255.0f;
			pixelData[w][h][2] = (GLfloat)b/(GLfloat)255.0;
		}
	}

	GLuint temp;
	glGenTextures(1, &temp);
	glBindTexture(GL_TEXTURE_2D, temp);
	landGen->setTexture(temp);
	glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_FLOAT, pixelData);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	debug("generateTerrain() : Generation complete.");

}
  
When I go and draw it:
void World::drawTerrain() {

	glLoadIdentity();

	glDisable(GL_DEPTH_TEST);						//Settings...

	glDisable(GL_LIGHTING);
	glDisable(GL_BLEND);
	glEnable(GL_TEXTURE_2D);

	glBindTexture(GL_TEXTURE_2D, landGen->getTexture());
	glBegin(GL_QUADS);
		glTexCoord2f(0, 0); glVertex3f(-1, -1, 0);
		glTexCoord2f(1, 0); glVertex3f(1, -1, 0);
		glTexCoord2f(1, 1); glVertex3f(1, 1, 0);
		glTexCoord2f(0, 1); glVertex3f(-1, 1, 0);
	glEnd();
}
 
It's drawn rotated 90 degrees to the left. Anyone know why, and how to fix it (w/o glRotate, because that will complicate what I'm trying to do with it later)? (It also did this when I used glDrawPixels) [edited by - MarauderIIC on May 25, 2004 12:03:31 AM]

Share this post


Link to post
Share on other sites
Advertisement
I got it.

Had to change

pixelData[w][h][0] = (GLfloat)r/(GLfloat)255.0f;
pixelData[w][h][1] = (GLfloat)g/(GLfloat)255.0f;
pixelData[w][h][2] = (GLfloat)b/(GLfloat)255.0;


to


pixelData[land.size()-1-h][w][0] = (GLfloat)r/(GLfloat)255.0f;
pixelData[land.size()-1-h][w][1] = (GLfloat)g/(GLfloat)255.0f;
pixelData[land.size()-1-h][w][2] = (GLfloat)b/(GLfloat)255.0;


(Flip the width & height around, start from the right of the array. Or whatever.)

[edited by - MarauderIIC on May 25, 2004 12:24:22 AM]

Share this post


Link to post
Share on other sites

  • 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!