行不显示
Line Not Showing
我写了这段代码来显示线段,但我不明白为什么线没有显示出来。有人可以帮忙吗?
#include<GL/glut.h>
#include<iostream>
void init()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 200.0, 0.0, 150.0);
}
void line_segment()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINE);
glVertex2i(180, 15);
glVertex2i(10, 145);
glEnd();
glFlush();
}
void main(int argc, char** argv)
{
glutInit(&argc, argv);
// optional
glutInitWindowSize(400, 300);
glutInitWindowPosition(50, 100);
// Till here
glutCreateWindow("Window.....");
init();
glutDisplayFunc(line_segment);
// without infinite loop window onl displayed for a very short time
glutMainLoop();
}
OUTPUT
GL_LINE
不是有效的 line primitive type. GL_LINE
is a polygon mode (see glPolygonMode
)。您要使用的原始类型是 GL_LINES
:
glBegin(GL_LINE);
glBegin(GL_LINES);
我写了这段代码来显示线段,但我不明白为什么线没有显示出来。有人可以帮忙吗?
#include<GL/glut.h>
#include<iostream>
void init()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 200.0, 0.0, 150.0);
}
void line_segment()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINE);
glVertex2i(180, 15);
glVertex2i(10, 145);
glEnd();
glFlush();
}
void main(int argc, char** argv)
{
glutInit(&argc, argv);
// optional
glutInitWindowSize(400, 300);
glutInitWindowPosition(50, 100);
// Till here
glutCreateWindow("Window.....");
init();
glutDisplayFunc(line_segment);
// without infinite loop window onl displayed for a very short time
glutMainLoop();
}
OUTPUT
GL_LINE
不是有效的 line primitive type. GL_LINE
is a polygon mode (see glPolygonMode
)。您要使用的原始类型是 GL_LINES
:
glBegin(GL_LINE);
glBegin(GL_LINES);