OpenGL中的画线

OpenGL中的画线,第1张

开始时,默认下是采用实线模式的,所以前面开始是实线,后面你启用了点划模式,所以后面是点划线,OpenGL保留了这个状态,经过glutMainLoop后,重画,采用的点划线的方式,所以前面的直线也是点划线了

用glutDisplayFunc()函数来画图。

我给你一个完整的程序,你把程序中的display函数换成DrawPoints就可以了

#include <GL/glut.h>

void display(void)

{

glClear (GL_COLOR_BUFFER_BIT)/* clear all pixels */

glColor3f (0.8, 1.0, 1.0)

glBegin(GL_POLYGON)/* draw white polygon with corners at(0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)*/

glVertex3f (0.25, 0.25, 0.0)

glVertex3f (0.75, 0.25, 0.0)

glVertex3f (0.75, 0.75, 0.0)

glVertex3f (0.25, 0.75, 0.0)

glEnd()

glFlush ()/* start processing buffered OpenGL routines */

}

void init (void)

{

glClearColor (0.0, 0.0, 0.0, 0.0)/* select clearing color */

glMatrixMode(GL_PROJECTION)

glLoadIdentity()

glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0)/* initialize viewing values */

}

int main(int argc, char** argv)

{

glutInit(&argc, argv)

glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB)/*Declare initial display mode(single buffer and RGBA).*/

glutInitWindowSize (250, 250)/*Declare initial window size.*/

glutInitWindowPosition (100, 100)/*Declare initial window position.*/

glutCreateWindow ("hello OpenGL")/*Open window with "hello"in its title bar.*/

init ()/*Call initialization routines.*/

glutDisplayFunc(display)/*Register callback function to display graphics.*/

glutMainLoop()/*Enter main loop and process events.*/

return 0 /* ANSI C requires main to return int. */

}

编译链接的方法请看链接:

http://www.360doc.com/content/10/0920/14/3359216_55103190.shtml

http://wenku.baidu.com/view/e4049c2d7375a417866f8f37.html


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12204048.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存