OpenGL,GL_MODELVIEW GL_PROJECTION的问题 [英] OpenGL, problems with GL_MODELVIEW GL_PROJECTION

查看:75
本文介绍了OpenGL,GL_MODELVIEW GL_PROJECTION的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我正在努力完成我的作业,但是在openGL的这些模型上我遇到了一些问题...任何想法,为什么我的抽奖没有发生?一件奇怪的事是,如果我改用gluPerspective,它就会起作用.

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;
}

推荐答案

您绘制的多边形不在glOrtho()设置的体积之内.您只会看到Z坐标在-1和1之间的点.

The polygon you draw is outside of the volume set up by glOrtho(). You will only see points with Z coordinate between -1 and 1.

这部分代码将导致绘图超出该范围.

This part of your code will cause drawing outside of that range.

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -5.0);

将glOrtho()的最后2个参数替换为-10,+ 10或删除该glTranslatef()

Either replace the glOrtho()'s last 2 parameters to something like -10, +10 or remove that glTranslatef()

这篇关于OpenGL,GL_MODELVIEW GL_PROJECTION的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆