Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gl/gl.h>
- #include <gl/glut.h>
- #include <stdio.h>
- float alpha, beta, theta;
- int x0, y0;
- void display(void) {
- glClear(GL_COLOR_BUFFER_BIT);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(20.0f, 1.0f, 1.0f, 10.0f);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(0.0f, 0.0f, 5.0f,
- 0.0f, 0.0f, 0.0f,
- 0.0f, 1.0f, 0.0f);
- glRotatef(alpha, 1.0f, 0.0f, 0.0f);
- glRotatef(beta, 0.0f, 1.0f, 0.0f);
- glRotatef(theta, 0.0f, 0.0f, 1.0f);
- glutWireCube(0.5);
- glFlush();
- glutSwapBuffers();
- }
- void update() {
- theta = theta + 1;
- glutPostRedisplay();
- }
- void onMouse(int button, int state, int x, int y) {
- if ( (button == GLUT_LEFT_BUTTON) & (state == GLUT_DOWN) ) {
- x0 = x; y0 = y;
- }
- }
- void onMotion(int x, int y) {
- alpha = (alpha + (y - y0));
- beta = (beta + (x - x0));
- x0 = x; y0 = y;
- glutPostRedisplay();
- }
- int main(void) {
- theta = 0;
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
- glutInitWindowSize(400, 400);
- glutInitWindowPosition(100, 100);
- glutCreateWindow("Ejemplo de menus");
- glutDisplayFunc(display);
- glutIdleFunc(update);
- glutMouseFunc(onMouse);
- glutMotionFunc(onMotion);
- glutMainLoop();
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement