我正在使用 OpenGL 的 glLineStipple() 函数来绘制虚线。一切正确,但输出屏幕上不显示虚线。输出屏幕完全空白。
这是我的代码:
#include <Windows.h>
#include <GL\glew.h>
#include <GL\glut.h>
#include <GL\freeglut.h>
void myInit()
{
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
}
void Display()
{
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_LINE_STIPPLE);
glLineStipple(1, 0x00FF); // Pattern: 0x00FF, Factor: 1
glBegin(GL_LINES);
glVertex2f(-0.5f, 0.0f);
glVertex2f(0.5f, 0.0f);
glEnd();
glDisable(GL_LINE_STIPPLE);
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);//Initialize the GLUT Library
glutInitDisplayMode(GLUT_SINGLE);
glutInitWindowSize(700, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("LineStipple");
myInit();
glutDisplayFunc(Display);//Callback Function
glutMainLoop();
return 0;
}