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增强技巧(四)----多边形图元及其点画模式的更多相关文章

  1. 绘制图形与3D增强技巧(五)----多边形图元的使用及其他

    1.注意多边形图元中的多边形只能是平面的,而且必须为凸多边形,且多边形的边不能弯曲 2.细分和边界,可以人为设置边界边和非边界边 glEdgeFlag(true)//接下来所有点均为边界边起点 glE ...

  2. 绘制图形与3D增强技巧(二)----直线图元之点画

    一.直线的点画模式:即并不完全填充所有像素来画一条直线,而是用点画的形式,间隔地画一条直线 首先启用点画模式: glEnable(GL_LINE_STIPPLE); 然后自定义创建自己的点画模式 gl ...

  3. 绘制图形与3D增强技巧(三)----三角形图元TRANGLE

    1. glBegin(GL_TRANGLES); ........ glend(); 2.多边形的环绕方向:逆时针和顺时针的正反面 GLFront(GL_CCW)和GLFront(GL_CW); 3. ...

  4. 绘制图形与3D增强技巧(二)----直线图元

    一. glBegin(GL_LINES); glend(); 二.线带和线环 glBegin(GL_LINE_STRIP); glend(); glBegin(GL_LINE_LOOP); glend ...

  5. 绘制图形与3D增强技巧(一)----点图元

    1.图元 1.点图元 glBegin(GL_POINTS); glend(); 程序:点图元的应用 #include "stdafx.h" #include<stdio.h& ...

  6. OpenGL学习进程(8)第六课:点、边和图形(三)绘制图形

    本节是OpenGL学习的第六个课时,下面介绍OpenGL图形的相关知识:     (1)多边形的概念: 多边形是由多条线段首尾相连而形成的闭合区域.OpenGL规定,一个多边形必须是一个“凸多边形”. ...

  7. OpenGL学习进程(4)第二课:绘制图形

    本节是OpenGL学习的第二个课时,下面介绍如何用点和线来绘制图形:     (1)用点的坐标来绘制矩形: #include <GL/glut.h> void display(void) ...

  8. cocos2d-x 绘制图形

    转载请注明出处:http://blog.csdn.net/oyangyufu/article/details/25841727 绘制图形例如以下:   程序代码: 须要又一次定义父类虚函数draw() ...

  9. 在Android中使用OpenGL ES进行开发第(三)节:绘制图形

    一.前期基础知识储备笔者计划写三篇文章来详细分析OpenGL ES基础的同时也是入门关键的三个点: ①OpenGL ES是什么?与OpenGL的关系是什么?——概念部分 ②使用OpenGLES绘制2D ...

随机推荐

  1. HTML 学习笔记 JavaScript(事件)

    事件流: 事件流: 描述的是从页面中接收事件的顺序 也可以理解为事件在页面中传播的顺序: 事件: 就是用户或浏览器自身执行的某种动作 例如 click(点击) load(加载) mouseover(鼠 ...

  2. 浅析MySQL数据碎片的产生(data free)

    浅析MySQL数据碎片的产生 2011-03-30 09:28 核子可乐译 51CTO 字号:T | T MySQL列表,包括MyISAM和InnoDB这两种最常见的类型,而根据经验来说,其碎片的产生 ...

  3. Java 集合系列05之 LinkedList详细介绍(源码解析)和使用示例

    概要  前面,我们已经学习了ArrayList,并了解了fail-fast机制.这一章我们接着学习List的实现类——LinkedList.和学习ArrayList一样,接下来呢,我们先对Linked ...

  4. Html5的一些引擎使用感触

    记得在2011年的时候,51CTO曾经采访我对H5的看法,因为当时Html5小组和雷友的关系,感觉是一片大火的形式,当时我的看法是:第一盈利模式不清晰,第二硬件跟不上,第三技术不成熟. 第一和第二点很 ...

  5. (转)c# 解析JSON的几种办法

    来自:http://blog.csdn.net/gaofang2009/article/details/6073029 欲成为海洋大师,必知晓海中每一滴水的真名. 刚开始只是想找一个转换JSON数组的 ...

  6. 我理解的Hanlder--android消息传递机制

    每一个学习Android的同学都会觉得Handler是一个神奇的东西,我也一样,开始我以为我懂了Handler的机制,后来发现自己是一知半解,昨天想想,我能否自己实现一个Handler,让子线程与Ac ...

  7. 处理Linux下subversion尝试连接自建的VisualSVN server报“Key usage violation in certificate has been detected”错误的问题

    在Linux下使用subversion尝试链接VisualSVN server搭建的svn库,可能会报下面错误, svn: OPTIONS of 'https://server.domain.loca ...

  8. PC互联网和移动互联网的本质差别

    网一代,我们先称为PC互联网,这大约可以从2010年作为分界,然后就是基于手机,及可穿戴的移动互联网. 在PC时代,软件都很庞大复杂,甚至客端端和网页混合,比如常见的桌面软件,Office及Photo ...

  9. 揭秘Facebook首个数据中心:全球15亿用户的账户信息都在这里

      投递人 itwriter 发布于 2016-07-14 17:41 评论(0) 原文链接 [收藏]  对于 Facebook.Google 这种体量的科技公司而言,数据中心应该是处于军事级别的保密 ...

  10. MyEclipse10中自动生成Hibernate的实体和xml配置文件

    前提:1.在项目中添加Hibernate支持 2.MyEclipse中已经创建好数据库连接 3.表已经建好并且有主键 步骤如下: 1.在DB Browser窗口的已打开连接节点中选中用户创建的所有的表 ...