OpenGL, problems with GL_MODELVIEW GL_PROJECTION...
Posted
by Marcos Roriz
on Stack Overflow
See other posts from Stack Overflow
or by Marcos Roriz
Published on 2010-05-09T21:25:00Z
Indexed on
2010/05/09
21:28 UTC
Read the original article
Hit count: 290
Guys, I'm trying to finish up my homework but I'm having some problems here on these models on openGL... any Idea why is my draw not happening? One thing that strange is that if I change to gluPerspective it works..
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
static int shoulder = 0;
static int elbow = 0;
void init(void) {
glClearColor(1.0, 1.0, 1.0, 0.0);
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
/* BASE */
glRotatef((GLfloat) shoulder, 0.0, 0.0, 1.0);
glTranslatef(1.0, 0.0, 0.0);
glPushMatrix();
//glScalef(2.0, 0.4, 1.0);
glBegin(GL_QUADS);
glColor3f(0, 0, 0);
glVertex2f(0.0, 0.0);
glVertex2f(0.0, 10.0);
glVertex2f(10.0, 10.0);
glVertex2f(10.0, 0.0);
glEnd();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
void reshape(int w, int h) {
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho((GLfloat)-w/2, (GLfloat)w/2, (GLfloat)-h/2, (GLfloat)h/2, -1.0, 1.0); // modo de projecao ortogonal
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -5.0);
}
void keyboard(unsigned char key, int x, int y) {
switch (key) {
case 's':
shoulder = (shoulder + 5) % 360;
glutPostRedisplay();
break;
case 'S':
shoulder = (shoulder - 5) % 360;
glutPostRedisplay();
break;
case 'e':
elbow = (elbow + 5) % 360;
glutPostRedisplay();
break;
case 'E':
elbow = (elbow - 5) % 360;
glutPostRedisplay();
break;
case 27:
exit(0);
break;
default:
break;
}
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(800, 400);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
© Stack Overflow or respective owner