Point不会在OpenGL中显示

时间:2010-07-31 15:39:57

标签: opengl

我正在尝试使用OpenGL绘制一个点,如下所示,但它只显示一个黑色窗口。有人能告诉我这是错误吗?

#include "stdafx.h"

#include <gl/GL.h>
#include <gl/GLU.h>
#include <gl/glut.h>

void init(void)
{
    glClearColor(0.0,0.0,0.0,0.0);

    glColor3f(1.0,0,1.0);
    glPointSize(10);
    //glShadeModel(GL_FLAT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D (0.0,0.0,400, 150);
}

void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    float pointSize = 5;
    glPointSize(10);
    glBegin(GL_POINTS); // render with points
    glVertex2i(50,40); //display a point
    glEnd();
    glFlush();
}

void reshape(int w,int h)
{
    glViewport(0,0,(GLsizei)w,(GLsizei)h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0,(GLdouble)w,0.0,(GLdouble)h,-1.0,1.0);
}

int _tmain(int argc, char* argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    glutInitWindowPosition(100, 100);
    glutInitWindowSize(400, 150);
    glutCreateWindow("Draw Simple Object");
    init();
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
}

2 个答案:

答案 0 :(得分:1)

您传递给gluOrtho2d的参数看起来不对。订单是左,右,上,下。您已将左侧和右侧都设置为0.0。根据您的glutInitWindowSize来电,我猜你想要的是gluOrtho2d(0.0, 400.0, 0.0, 150.0);(或者gluOrtho2d(0.0, 400.0, 150.0, 0.0);)。

答案 1 :(得分:0)

你画的点是黑色的,背景也是吗? 您是否尝试将此行添加到显示功能的开头:

glClearColor(1.0f,1.0f,1.0f,1.0f);