使用GL_LINES会导致性能下降吗?

时间:2020-04-22 17:22:40

标签: c++ opengl glut freeglut

我试图在OpenGL中画一条简单的线:

#include "stdafx.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <freeglut.h>

float startX = -180.0f;
float startZ = -100.0f;

float qtyX = 36;
float qtyZ = 20;

float red = 0.0f, green = 0.0f, blue = 0.0f;

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

void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    glLoadIdentity();

    gluLookAt(0.0, 50.0f, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0);

    glBegin(GL_LINES);
    glVertex3f(0.0f, 0.0f, 0.0f);
    glVertex3f(50.0f, 50.0f, 50.0f);
    glEnd();

    //glutWireSphere(20.0f, 20.0f, 20.0f);

    glutSwapBuffers();
    glFlush();
}

void reshape(int w, int h)
{
    glViewport(0, 0, (GLsizei)w, (GLsizei)h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-64.0, 64.0, -36.0, 36.0, 10, 10000.0);

    glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(1280, 720);
    glutInitWindowPosition(100, 100);
    glutCreateWindow(argv[0]);
    init();
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutReshapeFunc(reshape);
    glutMainLoop();
    return 0;
}

但是,当我运行程序时,性能显着下降,然后在几秒钟后,它停止响应(我必须运行任务管理器并强制退出程序)。但是,当我禁用线条并绘制glutWireSphere(或多边形)时,性能是正常的。

我的代码有问题吗?还是不赞成GL_LINES?

Windows 10、1070 MaxQ,Visual Studio

0 个答案:

没有答案