什么会导致openGL点看起来像虚线?我想画两条不同的线。一个包含破折号,另一个包含点。但是当我编译并运行我的程序时,虚线应该是破折号。这是我的代码:
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h> // (or others, depending on the system in use)
//#include <stdlib.h>
void init()
{
glClearColor (1.0, 1.0, 1.0, 0.0); /* Set display-window color to white.
r,g,b,alpha alpha 0.0 transparent */
glMatrixMode (GL_PROJECTION); // Set projection parameters.
gluOrtho2D (0.0, 250.0, 0.0, 250.0); // Set display area
}
void lineSegment()
{
glClear (GL_COLOR_BUFFER_BIT); // Clear display window. color buffer
glColor3f (0.0, 0.0, 1.0); // Set line segment color to green.
//glEnable(GL_LINE_STIPPLE);
int p1 [] = {0,80};
int p2 [] = {50, 50};
int p3 [] = {100, 100};
int p4 [] = {150, 75};
int p5 [] = {200, 120};
int p6 [] = {0, 50};
int p7 [] = {50, 100};
int p8 [] = {100,80 };
int p9 [] = {150, 150};
int p10 [] = {200, 60};
//double width dashed line
glEnable(GL_LINE_STIPPLE);
glLineWidth(2);
glLineStipple (1, 0x00FF); /* dashed */
glBegin(GL_LINE_STRIP);
glVertex2iv (p1);
glVertex2iv(p2);
glVertex2iv (p3);
glVertex2iv (p4);
glVertex2iv (p5);
glDisable (GL_LINE_STIPPLE);
glEnd();
glColor3f (1.0, 0.0, 1.0); // Set line segment color to green.
glEnable(GL_LINE_STIPPLE);
glLineWidth(3);
glLineStipple (1, 0x0101); /* dotted */
glBegin(GL_LINE_STRIP);
glVertex2iv (p6);
glVertex2iv(p7);
glVertex2iv (p8);
glVertex2iv (p9);
glVertex2iv (p10);
glDisable (GL_LINE_STIPPLE);
glEnd();
glFlush ( ); // Process all OpenGL routines as quickly as possible.
}
int main(int argc, char *argv[])
{
glutInit (&argc, argv); // Initialize GLUT.
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); // Set display mode, single buffering.
glutInitWindowPosition (50, 100); // Set top-left display-window position.
glutInitWindowSize (400, 300); // Set display-window width and height.
glutCreateWindow ("Dash and dots "); // Create display window.
init( ); // Execute initialization procedure.
glutDisplayFunc (lineSegment); // Send graphics to display window.
glutMainLoop ( ); // Display everything and wait.
return EXIT_SUCCESS;
}
答案 0 :(得分:1)
将虚线上的线宽设置为1.0
。