首页 技术 正文
技术 2022年11月14日
0 收藏 997 点赞 2,991 浏览 751 个字

开始看计算机图形学和OpenGL,挺有意思就自己随便写了一些效果。

以中间点坐标为圆心,计算每一点和圆心距离,根据距离算出一个RGB值,于是整体便呈现环形分布。

代码如下:

 #include <math.h> #include <GL/glut.h> void init() {     glClearColor(0.0, 0.0, 0.0, 0.0);     glMatrixMode(GL_PROJECTION);     gluOrtho2D(0.0, 600.0, 0.0, 600.0); } void lineSegment() {     glClear(GL_COLOR_BUFFER_BIT);     double r = 300.0;     glBegin(GL_POINTS);         ; i<=; ++i) ; j<=; ++j) {             double dis = sqrt((i-r)*(i-r)+(j-r)*(j-r));             double diff = fabs(dis-r);              - diff / r;             depth *= depth;             depth *= depth;             depth *= depth;             glColor3f(-depth, depth, depth);             glVertex2i(i, j);         }     glEnd();     glFlush(); } int main(int argc, char *argv[]) {     glutInit(&argc, argv);     glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);     glutInitWindowPosition(, );     glutInitWindowSize(, );     glutCreateWindow("OpenGL 3D View");     init();     glutDisplayFunc(lineSegment);     glutMainLoop();     ; }

运行效果如下,具体参数懒得调了,随便调调就能出不同的效果。

OpenGL绘制环形渐变

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,027
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,518
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,365
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,146
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,780
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,857