Hey. I have this code
#include <iostream>
#include <GLUT/GLUT.h>
using namespace std;
void display();
void reshape(int, int);
void idle();
void drawTile(int, int);
int world[32][32];
int main(int argc, char ** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize(640, 480);
glutCreateWindow("GLUT program");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
glutMainLoop();
return 0;
};
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for (int y = 0; y < 32; y++){
for (int x = 0; x < 32; x++){
if ((x+y)%2){
drawTile(x*16, y*8);
};
};
};
glutSwapBuffers();
};
void reshape(int width, int height){
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, width, height, 0);
glMatrixMode(GL_MODELVIEW);
};
void idle(){
/* code */
glutPostRedisplay();
};
void drawTile(int x, int y){
glColor3b(x, y, 127);
glBegin(GL_QUADS);
glVertex3i(x , y , (y )*-1);
glVertex3i(x-16, y+8 , (y+8 )*-1);
glVertex3i(x , y+16, (y+16)*-1);
glVertex3i(x+16, y+8 , (y+8 )*-1);
glEnd();
};
Said code doesn’t exactly work though. It doesn’t show the squares. After some analysis and variable changing, I concluded that Z can only be -1, 0, 1. I suspect this is due to clipping. Why is this, and how can I fix it? I would simply like to add some depth to my squares.