问题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;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

最新文章

  1. OpenCV特征点检测------ORB特征
  2. fatal: could not read Username for &#39;https://github.com&#39;: No such file or directo
  3. Python 文件操作函数
  4. ytu 2011: C语言实验——找中间数(水题)
  5. Android 代码混淆 防止反编译
  6. shell脚本中切换用户并执行命令
  7. sed and awk学习笔记
  8. Ejection chain 与交错路
  9. 1002 GTY&#39;s birthday gift
  10. discuz 重新定义jquery的$
  11. java方法的重载
  12. windows phone 之笔势
  13. HDU 5792 World is Exploding
  14. Android应用开发基础篇(5)-----Handler与多线程
  15. QT全平台设置图标,全平台静态编译 good
  16. android - 解决“应用自定义权限重名”
  17. 5.前端基于react,后端基于.net core2.0的开发之路(5) 配置node层,session设置、获取,请求拦截
  18. aspectj 简单的模拟权限检查、事务、日志记录
  19. TCP时间获取程序
  20. Confluence 6 指派空间权限概念

热门文章

  1. jquery如何实现动态增加选择框
  2. (十一)RabbitMQ消息队列-如何实现高可用
  3. JSP自己定义标签
  4. iOS开发Quarz2D 九:图片加水印
  5. C运行时库(C Run-time Library)详解(提供的另一个最重要的功能是为应用程序添加启动函数。Visual C++对控制台程序默认使用单线程的静态链接库,而MFC中的CFile类已暗藏了多线程)
  6. js进阶 11-17 juqery如何查找一个元素的同级元素
  7. jquery-8 jquery如何处理css样式
  8. jquery或js 获取url参数
  9. 【LeetCode-面试算法经典-Java实现】【107-Binary Tree Level Order Traversal II(二叉树层序遍历II)】
  10. 排序算法 基于Javascript