A simple openGL problem I need help with

Ok, so I have been having a lot of problems with uploading textures, so I said "fuck it." I decided to make a sort of texture plate program, that takes numbers from a text file, and those numbers determine colors on a square plate. My problem, is that the colors get flipped. If I had the number for brown at the top, a brown square bit appears at the bottom when I compile. But it isn't getting mirrored, (meaning left becomes right, top becomes bottom), but it's just getting turned upside-down. I feel like it has to do with a for-loop. Here's my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

#include <string>
#include <fstream>
#include <cmath>
#include <glut.h>
#include <GL\GLU.h>

using namespace std;

const int MAX_DIMENSIONS = 50;//doesn't have to be 50; I just set it to 50 because I don't want to have to edit a text file any larger than 50x50 :)
int dimensions[] = {14, 3, 50, 0, 0, 0, 0, 0, 0, 0, 0};
int texture[10][MAX_DIMENSIONS*2][MAX_DIMENSIONS*2];
char Ctexture[MAX_DIMENSIONS][MAX_DIMENSIONS];
float R[] = {0, 1, 0, 1, 1, 0, .5, 1, .9, .5}; //black, white, blue, red, yellow, green, purple, pink, orange, gray
float G[] = {0, 1, 0, 0, 1, 1,  0, 0, .5, .5}; //  0      1      2    3     4       5      6      7      8       9
float B[] = {0, 1, 1, 0, 0, 0, .5, .8, 0, .5};
float plateSize = .5;

void load_plate(const char *_filename, const int ID){
	ifstream myFile;
	myFile.open(_filename);
	string fileLine[MAX_DIMENSIONS]; 
	int i = 0;
	while(myFile.good()){
		getline(myFile, fileLine[i]);
		i++;
	}
	for (int a = 0; a < dimensions[ID]; a++) {	
		int e = 0;
		for (int b = 0; b < dimensions[ID]*2-1; b+=2) {
			Ctexture[a][e] = fileLine[a].at(b);
			e++;
		}
	}
	for (int a = 0; a < dimensions[ID]; a++) {
		for (int b = 0; b < dimensions[ID]; b++) {
			if      (Ctexture[a][b] == '0')   { texture[ID][a][b] = 0;}
			else if (Ctexture[a][b] == '1')   { texture[ID][a][b] = 1;}
			else if (Ctexture[a][b] == '2')   { texture[ID][a][b] = 2;}
			else if (Ctexture[a][b] == '3')   { texture[ID][a][b] = 3;}
			else if (Ctexture[a][b] == '4')   { texture[ID][a][b] = 4;}
			else if (Ctexture[a][b] == '5')   { texture[ID][a][b] = 5;}
			else if (Ctexture[a][b] == '6')   { texture[ID][a][b] = 6;}
			else if (Ctexture[a][b] == '7')   { texture[ID][a][b] = 7;}
			else if (Ctexture[a][b] == '8')   { texture[ID][a][b] = 8;}
			else if (Ctexture[a][b] == '9')   { texture[ID][a][b] = 9;}
		}
	}
	myFile.close();
}
void drawSquare(float x, float y, float z, int myDimensions) {
	glPushMatrix();
	glBegin(GL_QUADS);
	glVertex3f(x, y, z);
	glVertex3f(x, y+plateSize/myDimensions, z);
	glVertex3f(x+plateSize/myDimensions, y+plateSize/myDimensions, z);
	glVertex3f(x+plateSize/myDimensions, y, z);
	glEnd();
	glPopMatrix();
}
void Reshape(int height, int width) {
	glClearColor(0, 0, 0, 1);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(60, (float)height/(float)width, 1, 100);
	glMatrixMode(GL_MODELVIEW);
}
void drawPlate(float x, float y, float z, int ID, int myDimensions) {	
	for (int i = 0; i < myDimensions; i++) {
		for (int j = 0; j < myDimensions; j++) {
			glColor3d(R[texture[ID][i][j]], G[texture[ID][i][j]], B[texture[ID][i][j]]);
			drawSquare(x+(j*(plateSize/myDimensions)), y+(i*(plateSize/myDimensions)), z, dimensions[ID]);
		}
	}
}
void makePlate(const char *_filename, float x, float y, float z, int ID, int dimensions) {
	load_plate(_filename, ID);
	drawPlate(x, y, z, ID, dimensions);
}
void Display(void){
	glClear(GL_COLOR_BUFFER_BIT);
	makePlate("texture1.txt", 0, 0, -4, 0, 14);
	makePlate("texture2.txt", -1.5, 0, -4, 1, 3);
	makePlate("texture3.txt", -1, -1, -4, 2, 50);
	glutSwapBuffers();
}
void Keyboard(unsigned char key, int x, int y) {
	switch(key){
		case'a':
			plateSize += .05;
			glutPostRedisplay();
		break;
		case's':
			plateSize -= .05;
			glutPostRedisplay();
		break;
	}
}
int main(int argc, char **argv){
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutInit(&argc, argv);
	glutInitWindowSize(500, 500);
	glutInitWindowPosition(100, 100);
	glutCreateWindow("Texture plate tests");
	glutReshapeFunc(Reshape);
	glutDisplayFunc(Display);
	glutKeyboardFunc(Keyboard);
	glutMainLoop();
}
Topic archived. No new replies allowed.