1
什麼會導致OpenGL點看起來像虛線?我試圖畫出兩條單獨的線。一個包含破折號,另一個包含點。但是,當我編譯和運行我的程序時,應該是虛線,顯示爲破折號。以下是我的代碼: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;
}