位置: 编程技术 - 正文
推荐整理分享opengl 绘制实心圆柱体(opengl画实体),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:opengl绘制虚线,opengl绘制任意图形,opengl画心形曲线,opengl画心形曲线,opengl绘制实心圆,opengl画实体,opengl画实心圆,opengl绘制实心三角形,内容如对您有帮助,希望把文章链接给更多的朋友!
glu中提供了一个绘制圆柱体的函数:
void gluCylinder( GLUquadric* quad, GLdouble base, GLdouble top, GLdouble height, GLint slices, GLint stacks )使用方法是:
GLUquadric *pObj; pObj = gluNewQuadric();
调用gluCylinder函数时,将pObj作为第一个参数传入。gluDeleteQuadric(pObj);
这样子绘制出的圆柱体是空心的:
我根据gluCylinder函数写了个函数,将两边封顶。
[cpp] view plaincopyvoid mySolidCylinder( GLUquadric* quad, GLdouble base, GLdouble top, GLdouble height, GLint slices, GLint stacks ) { glColor3f(.0/, 0.0, .0/.0); gluCylinder(quad, base, top, height, slices, stacks); //top DrawCircleArea(0.0, 0.0, height, top, slices); //base DrawCircleArea(0.0, 0.0, 0.0, base, slices); } GLvoid DrawCircleArea(float cx, float cy, float cz, float r, int num_segments) { GLfloat vertex[4]; const GLfloat delta_angle = 2.0*M_PI/num_segments; glBegin(GL_TRIANGLE_FAN); vertex[0] = cx; vertex[1] = cy; vertex[2] = cz; vertex[3] = 1.0; glVertex4fv(vertex); //draw the vertex on the contour of the circle for(int i = 0; i < num_segments ; i) { vertex[0] = std::cos(delta_angle*i) * r cx; vertex[1] = std::sin(delta_angle*i) * r cy; vertex[2] = cz; vertex[3] = 1.0; glVertex4fv(vertex); } vertex[0] = 1.0 * r cx; vertex[1] = 0.0 * r cy; vertex[2] = cz; vertex[3] = 1.0; glVertex4fv(vertex); glEnd(); } [cpp] view plaincopyvoid mySolidCylinder( GLUquadric* quad, GLdouble base, GLdouble top, GLdouble height, GLint slices, GLint stacks ) { glColor3f(.0/, 0.0, .0/.0); gluCylinder(quad, base, top, height, slices, stacks); //top DrawCircleArea(0.0, 0.0, height, top, slices); //base DrawCircleArea(0.0, 0.0, 0.0, base, slices); } GLvoid DrawCircleArea(float cx, float cy, float cz, float r, int num_segments) { GLfloat vertex[4]; const GLfloat delta_angle = 2.0*M_PI/num_segments; glBegin(GL_TRIANGLE_FAN); vertex[0] = cx; vertex[1] = cy; vertex[2] = cz; vertex[3] = 1.0; glVertex4fv(vertex); //draw the vertex on the contour of the circle for(int i = 0; i < num_segments ; i) { vertex[0] = std::cos(delta_angle*i) * r cx; vertex[1] = std::sin(delta_angle*i) * r cy; vertex[2] = cz; vertex[3] = 1.0; glVertex4fv(vertex); } vertex[0] = 1.0 * r cx; vertex[1] = 0.0 * r cy; vertex[2] = cz; vertex[3] = 1.0; glVertex4fv(vertex); glEnd(); }最终绘制出的圆柱体:
Opengl 添加纹理 #includestdio.h#includewindows.h//HeaderFileForWindows#includeglgl.h//HeaderFileForTheOpenGLLibrary#includeglglu.h//HeaderFileForTheGLuLibrary#includeglglut.h//HeaderFileForTheGlauxLibrary#incl
cocos2dx吸蓝效果实现opengl绘制 cocos2dx想做一些比较炫的效果,单纯依靠引擎封装提供的一些东西毕竟有限,最近项目是用opengl绘制一些效果出来,代码如下:封装类效果类GoodDropEffects
错误error LNK: 无法解析的外部符号 _auxDIBImageLoadW@4 OpenGL编程时VS编译器报错:错误1errorLNK:无法解析的外部符号_auxDIBImageLoadW@4,该符号在函数p0解决办法:在cpp头部加入如下代码:#includeglaux.h#pragmacomment(li
标签: opengl画实体
本文链接地址:https://www.jiuchutong.com/biancheng/369467.html 转载请保留说明!友情链接: 武汉网站建设