witam, mam problem z poprawnym napisaniem programu który zachowuje proporcje figur w oknie, chciałem prosić o wskazanie błędu.
pozdrawiam
#include <GL/freeglut.h>
/*
* program wyswietla szescian z zachowaniem proporcji
*/
const int width = 640;
const int height = 480;
const float a = 1.0;
float fovy = 45.0, aspect = 1.0, near_ = 0.1, far_ = 10.0;//parametry dla gluPerspective();
void uklad(){
glBegin(GL_LINES);
glColor3f(0.0, 1.0, 0.0); //zielona oś X
glVertex3f(-8.0, 0.0, 0.0);
glVertex3f( 8.0, 0.0, 0.0);
glColor3f(0.0, 0.0, 1.0); // niebieska oś Y
glVertex3f(0.0, -8.0, 0.0);
glVertex3f(0.0, 8.0, 0.0);
glColor3f(1.0, 0.0, 0.0); // czerwona oś Z
glVertex3f(0.0, 0.0, -8.0);
glVertex3f(0.0, 0.0, 8.0);
glEnd();
}
void sciana(){
glBegin(GL_QUADS);
glVertex3f(-a / 2, 0.0, a / 2);
glVertex3f(-a / 2, 0.0, -a / 2);
glVertex3f( a / 2, 0.0, -a / 2);
glVertex3f( a / 2, 0.0, a / 2);
glEnd();
}
void szescian(){
//dolna sciana
glPushMatrix();
glLoadIdentity();
glTranslatef(0.0, -a /2, 0.0);
glColor3f(0.0, 0.0, 1.0);
sciana();
glPopMatrix();
//gorna sciana
glPushMatrix();
glLoadIdentity();
glTranslatef(0.0, a /2, 0.0);
glColor3f(0.0, 1.0, 1.0);
sciana();
glPopMatrix();
//lewa sciana
glPushMatrix();
glLoadIdentity();
glRotatef(90.0, 0.0, 0.0, 1.0);
glTranslatef(0.0, a /2, 0.0);
glColor3f(0.0, 1.0, 0.0);
sciana();
glPopMatrix();
//prawa sciana
glPushMatrix();
glLoadIdentity();
glRotatef(90.0, 0.0, 0.0, 1.0);
glTranslatef(0.0, -a /2, 0.0);
glColor3f(1.0, 1.0, 0.0);
sciana();
glPopMatrix();
//tylna sciana
glPushMatrix();
glLoadIdentity();
glRotatef(90.0, -1.0, 0.0, 0.0);
glTranslatef(0.0, a /2, 0.0);
glColor3f(1.0, 0.0, 0.0);
sciana();
glPopMatrix();
//przednia sciana
glPushMatrix();
glLoadIdentity();
glRotatef(90.0, -1.0, 0.0, 0.0);
glTranslatef(0.0, -a /2, 0.0);
glColor3f(0.4, 1.0, 0.0);
sciana();
glPopMatrix();
}
void display()
{
glClearColor(0.0,0.0,0.0,1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);//"czyszczenie" tła okan i bufora głębokosci
glEnable(GL_DEPTH_TEST);//włącznie algorytmu zasłaniania
//glMatrixMode(GL_PROJECTION);
//glLoadIdentity();
//gluPerspective(60.0, 1.0, 0.1, 10.0); //bryła widzenia perspektywicznego
//gluLookAt(2.0,2.0,2.0, 0.0,0.0,0.0, 0.0,1.0,0.0);//obserwator
//glMatrixMode(GL_MODELVIEW);
//glLoadIdentity();
uklad();
szescian();
glFlush();
}
void odrysuj(int width, int height){
float h = float(height), w = float(width);
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fovy, w/h, near_, far_);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowSize(width, height);
glutInitWindowPosition(100,100);
glutCreateWindow("Scena testowa");
glutDisplayFunc(display);
glutReshapeFunc(odrysuj);
glutMainLoop();
return 0;
}