绘制图形与3D增强技巧(四)----多边形图元及其点画模式
1.四边形图元
glBegin(GL_QUADS);
glend();
2.通用多边形
glBegin(GL_POLYGONS);
glend();
3.多边形点画模式
glenable(GL_POLYGON_STIPPLE);
glPolygonStipple(pBitmp);
其中pBitmap为一块指定了数据区域的指针,
#include "stdafx.h" // PStipple.cpp
// OpenGL SuperBible
// Demonstrates OpenGL Polygon Stippling
// Program by Richard S. Wright Jr.
#include<GL\glut.h>
#include <math.h> // Define a constant for the value of PI
#define GL_PI 3.1415f // Rotation amounts
static GLfloat xRot = 0.0f;
static GLfloat yRot = 0.0f; // Bitmap of camp fire
GLubyte fire[] = { 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xc0,
0x00, 0x00, 0x01, 0xf0,
0x00, 0x00, 0x07, 0xf0,
0x0f, 0x00, 0x1f, 0xe0,
0x1f, 0x80, 0x1f, 0xc0,
0x0f, 0xc0, 0x3f, 0x80,
0x07, 0xe0, 0x7e, 0x00,
0x03, 0xf0, 0xff, 0x80,
0x03, 0xf5, 0xff, 0xe0,
0x07, 0xfd, 0xff, 0xf8,
0x1f, 0xfc, 0xff, 0xe8,
0xff, 0xe3, 0xbf, 0x70,
0xde, 0x80, 0xb7, 0x00,
0x71, 0x10, 0x4a, 0x80,
0x03, 0x10, 0x4e, 0x40,
0x02, 0x88, 0x8c, 0x20,
0x05, 0x05, 0x04, 0x40,
0x02, 0x82, 0x14, 0x40,
0x02, 0x40, 0x10, 0x80,
0x02, 0x64, 0x1a, 0x80,
0x00, 0x92, 0x29, 0x00,
0x00, 0xb0, 0x48, 0x00,
0x00, 0xc8, 0x90, 0x00,
0x00, 0x85, 0x10, 0x00,
0x00, 0x03, 0x00, 0x00,
0x00, 0x00, 0x10, 0x00 }; // Called to draw scene
void RenderScene(void)
{
// Clear the window
glClear(GL_COLOR_BUFFER_BIT); // Save matrix state and do the rotation
glPushMatrix();
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
glRotatef(yRot, 0.0f, 1.0f, 0.0f); // Begin the stop sign shape,
// use a standard polygon for simplicity
glBegin(GL_POLYGON);
glVertex2f(-20.0f, 50.0f);
glVertex2f(20.0f, 50.0f);
glVertex2f(50.0f, 20.0f);
glVertex2f(50.0f, -20.0f);
glVertex2f(20.0f, -50.0f);
glVertex2f(-20.0f, -50.0f);
glVertex2f(-50.0f, -20.0f);
glVertex2f(-50.0f, 20.0f);
glEnd(); // Restore transformations
glPopMatrix(); // Flush drawing commands
glutSwapBuffers();
} // This function does any needed initialization on the rendering
// context.
void SetupRC()
{
// Black background
glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); // Set drawing color to red
glColor3f(1.0f, 0.0f, 0.0f); // Enable polygon stippling
glEnable(GL_POLYGON_STIPPLE); // Specify a specific stipple pattern
glPolygonStipple(fire);
} void SpecialKeys(int key, int x, int y)
{
if(key == GLUT_KEY_UP)
xRot-= 5.0f; if(key == GLUT_KEY_DOWN)
xRot += 5.0f; if(key == GLUT_KEY_LEFT)
yRot -= 5.0f; if(key == GLUT_KEY_RIGHT)
yRot += 5.0f; if(key > 356.0f)
xRot = 0.0f; if(key < -1.0f)
xRot = 355.0f; if(key > 356.0f)
yRot = 0.0f; if(key < -1.0f)
yRot = 355.0f; // Refresh the Window
glutPostRedisplay();
} void ChangeSize(int w, int h)
{
GLfloat nRange = 100.0f; // Prevent a divide by zero
if(h == )
h = ; // Set Viewport to window dimensions
glViewport(, , w, h); // Reset projection matrix stack
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // Establish clipping volume (left, right, bottom, top, near, far)
if (w <= h)
glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange);
else
glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange); // Reset Model view matrix stack
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
} int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow("Polygon Stippling");
glutReshapeFunc(ChangeSize);
glutSpecialFunc(SpecialKeys);
glutDisplayFunc(RenderScene);
SetupRC();
glutMainLoop(); return ;
}
绘制图形与3D增强技巧(四)----多边形图元及其点画模式的更多相关文章
- 绘制图形与3D增强技巧(五)----多边形图元的使用及其他
1.注意多边形图元中的多边形只能是平面的,而且必须为凸多边形,且多边形的边不能弯曲 2.细分和边界,可以人为设置边界边和非边界边 glEdgeFlag(true)//接下来所有点均为边界边起点 glE ...
- 绘制图形与3D增强技巧(二)----直线图元之点画
一.直线的点画模式:即并不完全填充所有像素来画一条直线,而是用点画的形式,间隔地画一条直线 首先启用点画模式: glEnable(GL_LINE_STIPPLE); 然后自定义创建自己的点画模式 gl ...
- 绘制图形与3D增强技巧(三)----三角形图元TRANGLE
1. glBegin(GL_TRANGLES); ........ glend(); 2.多边形的环绕方向:逆时针和顺时针的正反面 GLFront(GL_CCW)和GLFront(GL_CW); 3. ...
- 绘制图形与3D增强技巧(二)----直线图元
一. glBegin(GL_LINES); glend(); 二.线带和线环 glBegin(GL_LINE_STRIP); glend(); glBegin(GL_LINE_LOOP); glend ...
- 绘制图形与3D增强技巧(一)----点图元
1.图元 1.点图元 glBegin(GL_POINTS); glend(); 程序:点图元的应用 #include "stdafx.h" #include<stdio.h& ...
- OpenGL学习进程(8)第六课:点、边和图形(三)绘制图形
本节是OpenGL学习的第六个课时,下面介绍OpenGL图形的相关知识: (1)多边形的概念: 多边形是由多条线段首尾相连而形成的闭合区域.OpenGL规定,一个多边形必须是一个“凸多边形”. ...
- OpenGL学习进程(4)第二课:绘制图形
本节是OpenGL学习的第二个课时,下面介绍如何用点和线来绘制图形: (1)用点的坐标来绘制矩形: #include <GL/glut.h> void display(void) ...
- cocos2d-x 绘制图形
转载请注明出处:http://blog.csdn.net/oyangyufu/article/details/25841727 绘制图形例如以下: 程序代码: 须要又一次定义父类虚函数draw() ...
- 在Android中使用OpenGL ES进行开发第(三)节:绘制图形
一.前期基础知识储备笔者计划写三篇文章来详细分析OpenGL ES基础的同时也是入门关键的三个点: ①OpenGL ES是什么?与OpenGL的关系是什么?——概念部分 ②使用OpenGLES绘制2D ...
随机推荐
- 链剖&LCT总结
在搞LCT之前,我们不妨再看看喜闻乐见的树链剖分. 树链剖分有一道喜闻乐见的例题:NOI2015 软件包管理器 如果你看懂题目了,你就会明白它是叫你维护一个树,这棵树是不会动的,要兹磁子树求和,子树修 ...
- Mysql数据库之Binlog日志使用总结
binlog二进制日志对于mysql数据库的重要性有多大,在此就不多说了.下面根据本人的日常操作经历,并结合网上参考资料,对binlog日志使用做一梳理: 一.binlog日志介绍1)什么是binlo ...
- iOS - 用 UIBezierPath 实现果冻效果
最近在网上看到一个很酷的下拉刷新效果(http://iostuts.io/2015/10/17/elastic-bounce-using-uibezierpath-and-pan-gesture/). ...
- 数据类型之记录(record)..With XXX do begin... end;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 type Mai ...
- MVC HTTP 错误 403.14 - Forbidden
HTTP 错误 403.14 - Forbidden Web 服务器被配置为不列出此目录的内容. 最可能的原因: 没有为请求的 URL 配置默认文档,并且没有在服务器上启用目录浏览. 可尝试的操作: ...
- PHP中$_SERVER的详细参数与说明
$_SERVER['PHP_SELF'] #当前正在执行脚本的文件名,与 document root相关. $_SERVER['argv'] #传递给该脚本的参数. $_SERVER['argc'] ...
- (转)DataMatrix编码2——伽罗华域运算
原文出处:http://blog.sina.com.cn/s/blog_4572df4e01019wsj.html 伽罗华域即有限域,RS编码在此域中进行运算,故不得不对其有所了解.DataMatri ...
- R统计分析处理
[翻译]Awesome R资源大全中文版来了,全球最火的R工具包一网打尽,超过300+工具,还在等什么? 阅读目录 0.前言 1.集成开发环境 2.语法 3.数据操作 4.图形显示 5.HTML部件 ...
- FFmpeg中HLS文件解析源码
不少人都在找FFmpeg中是否有hls(m3u8)解析的源码,其实是有的.就是ffmpeg/libavformat/hlsproto.c,它依赖的文件也在那个目录中. 如果要是单纯想解析HLS的话,建 ...
- struts2使用Convention Plugin在weblogic上以war包部署时,找不到Action的解决办法
环境: struts 2.3.16.3 + Convention Plugin 2.3.16.3 实现零配置 现象:以文件夹方式部署在weblogic(10.3.3)上时一切正常,换成war包部署,运 ...