绘制图形与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 ...
随机推荐
- QT 数据库编程二
//logindlg.cpp #include "logindlg.h" #include <QGridLayout> #include <QHBoxLayout ...
- silverlight 4 tools for vs2010无法在vs2010 SP1上安装的解决办法
环境:英文版vs2010 sp1 + vs2013 RC 90天体验版 原来可以正常做silverilght 4 项目开发,今天因为vs2013 RC过了90天体验期,卸载时顺带把Silverlihg ...
- Python2.4-原理之函数
此节来自于<Python学习手册第四版>第四部分 一.函数基础 函数的作用在每个编程语言中都是大同小异的,,这个表是函数的相关语句和表达式. 1.编写函数,a.def是可执行代码,pyth ...
- .NET技术在中国为什么老被人嫌弃
这个话题有点自黑的意思,我从.NET 1.1开始玩.NET,到现在已经11年了,我是看着.NET成长起来,在中国壮大的,也见证了近几年.NET被各种嫌弃,其实说到底还是中国的架构师太少,我是说真正懂行 ...
- WinObjc - 使用iOS项目生成通用Windows应用
Github上一周年的WinObjc项目最近发布了预览版本,终于等到了这一天.WinObjc项目就是Build 2015大会上微软宣布的Project IslandWood项目,致力于将iOS应用快速 ...
- Bash on Windows 抢鲜测试 -- 介绍及安装
前言 微软在上周的Windows BUILD大会上宣布,WIN10将引入原生Bash,并将很快在技术预览版中推出. 如此一来,windows的命令行工具就不再只有cmd和powershell了,我们可 ...
- 关于安装Visual Studio 2015 RC版卡主不动的解决方案
在官方网站下载了vs_community.exe自动下载安装的软件进行安装,安装到github时候 卡了1个小时 一直显示正在获取,遂感觉不大对劲,使用了FQ程序,过了2分钟果然正常获取安装,进入了下 ...
- DateTime.Now.ToString() 用法
//2008年4月24日 System.DateTime.Now.ToString("D"); //2008-4-24 System.DateTime.Now.ToString(& ...
- Echarts的相关问题记录与应用
一.相关问题记录: 1.对图表的div进行隐藏操作,使用hide()或display:none,重新展示时,会造成图表无法获取高度,导致图表的高宽不符合预期: 解决方法:最后调用一下resize()函 ...
- CSS中的行为——expression
IE5及其以后版本支持在CSS中使用expression,用来把CSS属性和Javascript脚本关联起来,这里的CSS属性可以是元素固有的属性,也可以是自定义属性.就是说CSS属性后面可以是一段J ...