问题1:根据源代码时,我发现的时候去敲门。不正确实施效果。哪里是不正确?没有源代码glPushAttrib(GL_LINE_STIPPLE) glPopAttrib()。所以会出现最后的下一次抽奖提供的资料重绘每次更新的虚线时间前覆盖已制定好点线。和谈栈处理,这样子在刷帧重绘才不会影响其它帧的绘制结果。(原因是什么眼下我也不清楚,预计是状态机的管理问题。要了解内部的绘制机制才行。
)可是每次手动加入压栈和弹栈太麻烦了,所以我处理C_style的宏定义形式去实现
问题2:reshape的操作屏蔽掉之后发现仅仅要display中正确设置窗体參数,还是能正常绘制的。。
问题来了,reshape不应该是我拉伸窗体才会触发的吗?可是情况如改动仍能正常显示。百思不得其解,求不吝赐教。!
改动1源代码例如以下:
#include "stdafx.h" #include <GL/freeglut.h> #define drawOneLine(x1,y1,x2,y2) glBegin(GL_LINES); glVertex2f((x1),(y1));glVertex2f((x2),(y2));glEnd(); void init(void) { glClearColor(0.0,0.0,0.0,0.0); glShadeModel(GL_FLAT); } void display(void) { //初初始化定义 窗体,我有益把这段搬出来測试reshape函数的调用,问题2: int w = 400,h =150; glViewport(0,0,static_cast<GLsizei>(w),static_cast<GLsizei>(h)); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0,static_cast<GLfloat>(w),0.0,static_cast<GLfloat>(h)); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //int i; glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glColor3f(1.0,1.0,1.0); glEnable(GL_LINE_STIPPLE); //1st row glPushAttrib(GL_LINE_STIPPLE); //以二进制读取,从低位開始绘制,第一个參数为拉伸參数 glLineStipple(1,0x0101); drawOneLine(50.0,125.0,150,125.0); glPopAttrib(); glPushAttrib(GL_LINE_STIPPLE); glLineStipple(1,0x00FF); drawOneLine(150.0,125.0,250.0,125.0); glPopAttrib(); glPushAttrib(GL_LINE_STIPPLE); glLineStipple(1,0x1c47); drawOneLine(250.0,125.0,350.0,125.0); glPopAttrib(); //2nd row glLineWidth(5.0); glPushAttrib(GL_LINE_STIPPLE); //以二进制读取,从低位開始绘制,第一个參数为拉伸參数 glLineStipple(1,0x0101); drawOneLine(50.0,100.0,150.0,100.0); glPopAttrib(); glPushAttrib(GL_LINE_STIPPLE); glLineStipple(1,0x00ff); drawOneLine(150.0,100.0,250.0,100.0); glPopAttrib(); glPushAttrib(GL_LINE_STIPPLE); glLineStipple(1,0x1c47); drawOneLine(250.0,100.0,350.0,100.0); glPopAttrib(); glLineWidth(1.0); //3rd row glPushAttrib(GL_LINE_STIPPLE); glLineStipple(1,0x1c47); glBegin(GL_LINE_STRIP); for (int i = 0; i < 7; i++) { glVertex2f(50.0+static_cast<GLfloat>(i*50.0),75.0); } glEnd(); glPopAttrib(); glDisable(GL_LINE_STIPPLE); glPopMatrix(); glFlush(); } void reshape(int w,int h) { } int _tmain(int argc, char * argv[]) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(400,150); glutInitWindowPosition(0,0); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutReshapeFunc(NULL); glutMainLoop(); return 0; }
正确源代码示范:
// Lines_P35.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <GL/freeglut.h> #define drawOneLine(scale,stipple,x1,y1,x2,y2) glPushAttrib(GL_LINE_STIPPLE); glLineStipple((scale),(stipple)); glBegin(GL_LINES); glVertex2f((x1),(y1));glVertex2f((x2),(y2)); glEnd(); glPopAttrib(); void init(void) { glClearColor(0.0,0.0,0.0,0.0); glShadeModel(GL_FLAT); } void display(void) { glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glColor3f(1.0,1.0,1.0); glEnable(GL_LINE_STIPPLE); //1st row //以二进制读取,从低位開始绘制。第一个參数为拉伸參数 drawOneLine(1,0x0101,50.0,125.0,150,125.0); drawOneLine(1,0x00FF,150.0,125.0,250.0,125.0); drawOneLine(1,0x1c47,250.0,125.0,350.0,125.0); //2nd row glLineWidth(5.0); //以二进制读取。从低位開始绘制。第一个參数为拉伸參数 drawOneLine(1,0x0101,50.0,100.0,150.0,100.0); drawOneLine(1,0x00ff,150.0,100.0,250.0,100.0); drawOneLine(1,0x1c47,250.0,100.0,350.0,100.0); glLineWidth(1.0); //3rd row glPushAttrib(GL_LINE_STIPPLE); glLineStipple(1,0x1c47); glBegin(GL_LINE_STRIP); for (int i = 0; i < 7; i++) { glVertex2f(50.0+static_cast<GLfloat>(i*50.0),75.0); } glEnd(); glPopAttrib(); //4th for (int i = 0; i < 6; i++) { drawOneLine(1,0x1c47,50.0+static_cast<GLfloat>(i*50.0),50.0,50.0+static_cast<GLfloat>(i+1)*50.0,50.0); } //5th drawOneLine(5,0x1c47,50.0,25.0,350.0,25.0); glDisable(GL_LINE_STIPPLE); glPopMatrix(); glFlush(); } void reshape(int w,int h) { glViewport(0,0,static_cast<GLsizei>(w),static_cast<GLsizei>(h)); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0,static_cast<GLfloat>(w),0.0,static_cast<GLfloat>(h)); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int _tmain(int argc, char * argv[]) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(400,150); glutInitWindowPosition(0,0); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMainLoop(); return 0; }
版权声明:本文博客原创文章,博客,未经同意,不得转载。
时间: 2024-09-27 17:23:40