///////////////////////////////////////////////////////////////////////////////
// main.cpp
// ========
// Example of OpenGL Tessellation
// Tessellation is used for subdividing concave planar polygons or polygons
// with intersecting edges into convex polygons. In this example, there are 3
// different types of models;
// 1) tessellate1(): a concave quad
// 2) tessellate2(): a quad with hole in it
// 3) tessellate3(): a star shape (5 vertices) with intersecting edges
//
// By using OpenGL tessellation operation, these 3 models will be converted
// into convex polygons. Note that all vertices of a polygon are lying on a
// same plane
// In this example, the actual OpenGL calls are recorded and printed out to
// console. Examine the output to see what tessellator does for you.
//
// AUTHOR: Song Ho Ahn (song.ahn@gmail.com)
// CREATED: 2003-05-06
// UPDATED: 2006-02-22
///////////////////////////////////////////////////////////////////////////////
#include <GL/glut.h>
#include <iostream>
#include <sstream>
#include <iomanip>
using std::stringstream;
using std::cout;
using std::cerr;
using std::endl;
using std::ends;
#ifndef CALLBACK
#define CALLBACK
#endif
// CALLBACK functions for GLU_TESS ////////////////////////////////////////////
// NOTE: must be declared with CALLBACK directive
void CALLBACK tessBeginCB(GLenum which);
void CALLBACK tessEndCB();
void CALLBACK tessErrorCB(GLenum errorCode);
void CALLBACK tessVertexCB(const GLvoid *data);
void CALLBACK tessVertexCB2(const GLvoid *data);
void CALLBACK tessCombineCB(const GLdouble newVertex[3], const GLdouble *neighborVertex[4],
const GLfloat neighborWeight[4], GLdouble **outData);
// GLUT CALLBACK functions ////////////////////////////////////////////////////
void displayCB();
void reshapeCB(int w, int h);
void timerCB(int millisec);
void idleCB();
void keyboardCB(unsigned char key, int x, int y);
void mouseCB(int button, int stat, int x, int y);
void mouseMotionCB(int x, int y);
// function declarations //////////////////////////////////////////////////////
void initGL();
int initGLUT(int argc, char **argv);
bool initSharedMem();
void clearSharedMem();
void initLights();
void setCamera(float posX, float posY, float posZ, float targetX, float targetY, float targetZ);
void drawString(const char *str, int x, int y, float color[4], void *font);
void drawString3D(const char *str, float pos[3], float color[4], void *font);
void showInfo();
const char* getPrimitiveType(GLenum type);
GLuint tessellate1();
GLuint tessellate2();
GLuint tessellate3();
// global variables ///////////////////////////////////////////////////////////
void *font = GLUT_BITMAP_8_BY_13;
bool mouseLeftDown;
bool mouseRightDown;
float mouseX, mouseY;
float cameraAngleX;
float cameraAngleY;
float cameraDistance;
int drawMode = 0;
GLuint listId1, listId2, listId3; // IDs of display lists
GLdouble vertices[64][6]; // arrary to store newly created vertices (x,y,z,r,g,b) by combine callback
int vertexIndex = 0; // array index for above array incremented inside combine callback
// DEBUG //
stringstream ss;
///////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
initSharedMem();
// init GLUT and GL
initGLUT(argc, argv);
initGL();
// perform tessellation and compile into display lists
listId1 = tessellate1(); // a concave quad
listId2 = tessellate2(); // a quad with a hole in it
listId3 = tessellate3(); // a self-intersecting star
// the last GLUT call (LOOP)
// window will be shown and display callback is triggered by events
// NOTE: this call never return main().
glutMainLoop(); /* Start GLUT event-processing loop */
return 0;
}
///////////////////////////////////////////////////////////////////////////////
// create a tessellation object and compile a quad into a display list
///////////////////////////////////////////////////////////////////////////////
GLuint tessellate1()
{
GLuint id = glGenLists(1); // create a display list
if(!id) return id; // failed to create a list, return 0
GLUtesselator *tess = gluNewTess(); // create a tessellator
if(!tess) return 0; // failed to create tessellation object, return 0
// define concave quad data (vertices only)
// 0 2
// \ \/ /
// \3 /
// \/
// 1
GLdouble quad1[4][3] = { {-1,3,0}, {0,0,0}, {1,3,0}, {0,2,0} };
// register callback functions
gluTessCallback(tess, GLU_TESS_BEGIN, (void (CALLBACK *)())tessBeginCB);
gluTessCallback(tess, GLU_TESS_END, (void (CALLBACK *)())tessEndCB);
gluTessCallback(tess, GLU_TESS_ERROR, (void (CALLBACK *)())tessErrorCB);
gluTessCallback(tess, GLU_TESS_VERTEX, (void (CALLBACK *)())tessVertexCB);
// tessellate and compile a concave quad into display list
// gluTessVertex() takes 3 params: tess object, pointer to vertex coords,
// and pointer to vertex data to be passed to vertex callback.
// The second param is used only to perform tessellation, and the third
// param is the actual vertex data to draw. It is usually same as the second
// param, but It can be more than vertex coord, for example, color, normal
// and UV coords which are needed for actual drawing.
// Here, we are looking at only vertex coods, so the 2nd and 3rd params are
// pointing same address.
glNewList(id, GL_COMPILE);
//glColor3f(1,1,1);
gluTessBeginPolygon(tess, 0); // with NULL data
gluTessBeginContour(tess);
gluTessVertex(tess, quad1[0], quad1[0]);
gluTessVertex(tess, quad1[1], quad1[1]);
gluTessVertex(tess, quad1[2], quad1[2]);
gluTessVertex(tess, quad1[3], quad1[3]);
gluTessEndContour(tess);
gluTessEndPolygon(tess);
glEndList();
gluDeleteTess(tess); // delete after tessellation
// DEBUG //
// print out actual GL calls that are performed
cout << endl;
cout << "1. Concave Quad\n";
cout << "===============\n";
cout << ss.str().c_str() << endl;
ss.str(""); // clear string buffer
return id; // return handle ID of a display list
}
///////////////////////////////////////////////////////////////////////////////
// tessellate a polygon with a hole and compile it into a display list
///////////////////////////////////////////////////////////////////////////////
GLuint tessellate2()
{
GLuint id = glGenLists(1); // create a display list
if(!id) return id; // failed to create a list, return 0
GLUtesselator *tess = gluNewTess(); // create a tessellator
if(!tess) return 0; // failed to create tessellation object, return 0
// define concave quad with a hole
// 0--------3
// | 4----7 |
// | | | |
// | 5----6 |
// 1--------2
GLdouble quad2[8][3] = { {-2,3,0}, {-2,0,0}, {2,0,0}, { 2,3,0},
{-1,2,0}, {-1,1,0}, {1,1,0}, { 1,2,0} };
// register callback functions
gluTessCallback(tess, GLU_TESS_BEGIN, (void (__stdcall*)(void))tessBeginCB);
gluTessCallback(tess, GLU_TESS_END, (void (__stdcall*)(void))tessEndCB);
gluTessCallback(tess, GLU_TESS_ERROR, (void (__stdcall*)(void))tessErrorCB);
gluTessCallback(tess, GLU_TESS_VERTEX, (void (__stdcall*)())tessVertexCB);
// tessellate and compile a concave quad into display list
glNewList(id, GL_COMPILE);
glColor3f(1,1,1);
gluTessBeginPolygon(tess, 0); // with NULL data
gluTessBeginContour(tess); // outer quad
gluTessVertex(tess, quad2[0], quad2[0]);
没有合适的资源?快使用搜索试试~ 我知道了~
tessellation_src_main.rar_Tessellation_凹多边形_凹多边形 opengl
共6个文件
dsw:1个
dev:1个
dsp:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 91 浏览量
2022-09-19
14:11:42
上传
评论
收藏 9KB RAR 举报
温馨提示
采用visual c++ 和 opengl绘制凹多边形的例子
资源详情
资源评论
资源推荐
收起资源包目录
tessellation_src_main.rar (6个子文件)
src
Makefile.win 939B
main.dsw 533B
main.dsp 4KB
main.cpp 28KB
tessellation.dev 943B
www.pudn.com.txt 218B
共 6 条
- 1
寒泊
- 粉丝: 85
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- (源码)基于SpringBoot和Vue的ELADMIN后台管理系统.zip
- rabbitmq-server-3.12.4-windows安装包
- rabbitmq-server-3.12.5-windows安装包
- (源码)基于SpringBoot框架的教材采购管理系统.zip
- rabbitmq-server-3.12.6-windows安装包
- C#企业人事工资管理系统源码数据库 SQL2008源码类型 WinForm
- 用于谷歌地球引擎的 TensorFlow 时间序列分析的 Python 笔记本CNN.ipynb
- (源码)基于Java的垃圾分类查询系统.zip
- rabbitmq-server-3.12.8-windows安装包
- rabbitmq-server-3.12.9-windows安装包
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0