Marcin Kaszuba

Members
  • Content count

    1
  • Joined

  • Last visited

Community Reputation

101 Neutral

About Marcin Kaszuba

  • Rank
    Newbie
  1. hello, I have problem with correct display wall cube. I use table vertex. Please help ;) I'm from Poland [CODE] /* * File: main.c * Author: marcin * * Created on 13 pa?dziernik 2012, 16:29 */ #include <stdio.h> #include <stdlib.h> #include <GL/freeglut.h> #include <math.h> /* * */ const float delta_alfa = 0.05; float alfa = 0.0; float a = 0.725; int widthWindow = 600; int heightWindow = 800; float r = 1.0; float fovy = 45.0, aspect = 1.0, near_ = 0.1, far_ = 10.0;//parametry dla gluPerspective() void ukladWspolrzednych(){ glBegin(GL_LINES); //linia x rozowa glColor3f(1.0, 0.0, 1.0); glVertex3f(5.0, 0.0, 0.0); glVertex3f(-5.0, 0.0, 0.0); //linia y zielona glColor3f(0.0, 1.0, 1.0); glVertex3f(0.0, 5.0, 0.0); glVertex3f(0.0, -5.0, 0.0); //linia z zolta glColor3f(1.0, 1.0, 0.0); glVertex3f(0.0, 0.0, 5.0); glVertex3f(0.0, 0.0, -5.0); glEnd(); } void szescian(){ static float wierzcholki[] = { 0.0, 0.0, 0.0,//0 0 0 0 0.75, 0.0, 0.0,//1 a 0 0 0.75, 0.0, 0.75,//2 a 0 a 0.0, 0.0, 0.75,//3 0 0 a 0.0, 0.75, 0.0,//4 0 a 0 0.75, 0.75, 0.0,//5 a a 0 0.75, 0.75, 0.75,//6 a a a 0.0, 0.75, 0.75 //7 0 a a }; float kolory[] = { 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0 }; glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glVertexPointer(3, GL_FLOAT, 0, wierzcholki); glColorPointer(3, GL_FLOAT, 0, kolory); static unsigned short dolnaSciana[] = {0, 1, 2, 3}; static unsigned short gornaSciana[] = {4, 5, 6, 7}; static unsigned short tylnaSciana[] = {0, 1, 4, 5}; static unsigned short przodSciana[] = {2, 3, 6, 7}; static unsigned short lewaSciana[] = {0, 3, 4, 7}; static unsigned short prawaSciana[] = {1, 2, 5, 6}; glDrawElements(GL_QUADS, 4, GL_UNSIGNED_SHORT, dolnaSciana); glDrawElements(GL_QUADS, 4, GL_UNSIGNED_SHORT, gornaSciana); glDrawElements(GL_QUADS, 4, GL_UNSIGNED_SHORT, tylnaSciana); glDrawElements(GL_QUADS, 4, GL_UNSIGNED_SHORT, przodSciana); glDrawElements(GL_QUADS, 4, GL_UNSIGNED_SHORT, lewaSciana); glDrawElements(GL_QUADS, 4, GL_UNSIGNED_SHORT, prawaSciana); } void anim(){ alfa += delta_alfa; glutPostRedisplay(); } void init(){ glClearColor(0.0, 0.0, 0.0, 1.0); glEnable(GL_DEPTH_TEST); } void odrysuj(int szerokosc, int wysokosc){ float h = wysokosc; float w = szerokosc; glViewport(0, 0, szerokosc, wysokosc); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(fovy, w/h, near_, far_); glMatrixMode(GL_MODELVIEW); } void scena(){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(2.0, 2.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.0); ukladWspolrzednych(); glRotatef(alfa, 0.0, 1.0, 0.0); //glTranslatef(r, 0.0, 0.0); glTranslatef(-a / 2, 0.0, -a / 2); szescian(); glFlush(); glutSwapBuffers(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutInitWindowSize(heightWindow, widthWindow); glutInitWindowPosition(100,100); glutCreateWindow("Scena testowa"); glutDisplayFunc(scena); glutReshapeFunc(odrysuj); glutIdleFunc(anim); init(); glutMainLoop(); return (EXIT_SUCCESS); } [/CODE]