资源简介
看书过后,用qt实现的一个把2维纹理贴到球面的工程,其中还包含混合光,采用opengl es 3.0;初学者可以学习下

代码片段和文件信息
#include “balltexturerender.h“
BallTextureRender::~BallTextureRender()
{
if(texture_){
texture_->destroy();
delete texture_;
}
}
void BallTextureRender::initsize(float r QImage &img)
{
program_.addCacheableShaderFromSourceFile(QOpenGLShader::Vertex“vsrc.vert“);
program_.addCacheableShaderFromSourceFile(QOpenGLShader::Fragment“fsrc.frag“);
program_.link();
r_ = r;
int angleSpan = 10; //弧度 = 角度 * PI / 180
for(int vAngle = -90; vAngle < 90; vAngle = vAngle + angleSpan){ //生成球面顶点
for(int hAngle = 0; hAngle <= 360; hAngle = hAngle + angleSpan){
float x0 = r * ::cos(vAngle * PI / 180) * ::cos(hAngle * PI / 180);
float y0 = r * ::cos(vAngle * PI / 180) * ::sin(hAngle * PI / 180);
float z0 = r * ::sin(vAngle * PI / 180);
float x1 = r * ::cos(vAngle * PI / 180) * ::cos((hAngle + angleSpan) * PI / 180);
float y1 = r * ::cos(vAngle * PI / 180) * ::sin((hAngle + angleSpan) * PI / 180);
float z1 = r * ::sin(vAngle * PI / 180);
float x2 = r * ::cos((vAngle + angleSpan) * PI / 180) * ::cos((hAngle + angleSpan) * PI / 180);
float y2 = r * ::cos((vAngle + angleSpan) * PI / 180) * ::sin((hAngle + angleSpan) * PI / 180);
float z2 = r * ::sin((vAngle + angleSpan) * PI / 180);
float x3 = r * ::cos((vAngle + angleSpan) * PI / 180) * ::cos(hAngle * PI / 180);
float y3 = r * ::cos((vAngle + angleSpan) * PI / 180) * ::sin(hAngle * PI / 180);
float z3 = r * ::sin((vAngle + angleSpan) * PI / 180);
points_ << x1 << y1 << z1 << x3 << y3 << z3
<< x0 << y0 << z0 << x1 << y1 << z1
<< x2 << y2 << z2 << x3 << y3 << z3;
}
}
texture_ = new QOpenGLTexture(img);
vbo_.create();
vbo_.bind();
vbo_.allocate(points_.constData()points_.count() * sizeof GLfloat);
}
void BallTextureRender::render(QOpenGLExtraFunctions *f QMatrix4x4 &pMatrix QMatrix4x4 &vMatrix QMatrix4x4 &mMatrix QVector3D &lightLocation QVector3D &camera)
{
f->glEnable(GL_DEPTH_TEST);
f->glEnable(GL_CULL_FACE);
program_.bind();
vbo_.bind();
f->glActiveTexture(GL_TEXTURE0 + 0);
program_.setUniformValue(“uPMatrix“pMatrix);
program_.setUniformValue(“uVMatrix“vMatrix);
program_.setUniformValue(“uMMatrix“mMatrix);
program_.setUniformValue(“uLightLocation“lightLocation);
program_.setUniformValue(“uCamera“camera);
program_.setUniformValue(“uR“r_);
program_.setUniformValue(“sTexture“0);
program_.enableAttributeArray(0);
program_.enableAttributeArray(1);
texture_->bind(0);
program_.setAttributeBuffer(0GL_FLOAT030);
program_.setAttributeBuffer(1GL_FLOAT030);
f->glDrawArrays(GL_TRIANGLES0points_.count() / 3);
program_.disableAttributeArray(0);
program_.disableAttributeArray(1);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 7 2018-10-01 10:00 balltexture\.git\COMMIT_EDITMSG
文件 316 2018-10-01 09:30 balltexture\.git\config
文件 73 2018-10-01 09:30 balltexture\.git\desc
文件 23 2018-10-01 09:30 balltexture\.git\HEAD
文件 478 2018-10-01 09:30 balltexture\.git\hooks\applypatch-msg.sample
文件 896 2018-10-01 09:30 balltexture\.git\hooks\commit-msg.sample
文件 3327 2018-10-01 09:30 balltexture\.git\hooks\fsmonitor-watchman.sample
文件 189 2018-10-01 09:30 balltexture\.git\hooks\post-update.sample
文件 424 2018-10-01 09:30 balltexture\.git\hooks\pre-applypatch.sample
文件 1638 2018-10-01 09:30 balltexture\.git\hooks\pre-commit.sample
文件 1348 2018-10-01 09:30 balltexture\.git\hooks\pre-push.sample
文件 4898 2018-10-01 09:30 balltexture\.git\hooks\pre-reba
文件 544 2018-10-01 09:30 balltexture\.git\hooks\pre-receive.sample
文件 1492 2018-10-01 09:30 balltexture\.git\hooks\prepare-commit-msg.sample
文件 3610 2018-10-01 09:30 balltexture\.git\hooks\update.sample
文件 689 2018-10-01 10:00 balltexture\.git\index
文件 240 2018-10-01 09:30 balltexture\.git\info\exclude
文件 516 2018-10-01 10:00 balltexture\.git\logs\HEAD
文件 516 2018-10-01 10:00 balltexture\.git\logs\refs\heads\master
文件 206 2018-10-01 09:30 balltexture\.git\logs\refs\remotes\origin\HEAD
文件 310 2018-10-01 10:00 balltexture\.git\logs\refs\remotes\origin\master
文件 642 2018-10-01 09:30 balltexture\.git\ob
文件 159 2018-10-01 10:00 balltexture\.git\ob
文件 583 2018-10-01 09:30 balltexture\.git\ob
文件 979 2018-10-01 09:30 balltexture\.git\ob
文件 320 2018-10-01 09:30 balltexture\.git\ob
文件 356 2018-10-01 09:30 balltexture\.git\ob
文件 271 2018-10-01 10:00 balltexture\.git\ob
文件 188 2018-10-01 09:30 balltexture\.git\ob
文件 136 2018-10-01 09:30 balltexture\.git\ob
............此处省略56个文件信息
相关资源
- powerdesigner 15.1 license key
- powerdesigner15.0的注册码license key
- 专业版 Visio 工具cn_visio_professional_20
- Bc衰变中的D波衰减器ηc211D2,ψ
- Microservices_Designing_Deploying
-
Design for em
bedded Image Processing on FPG - Concurrency in Go Tools and Techniques for Dev
- HP商用彩色喷墨打印机Business Inkjet 2
- Assembly Language for x86 Processors (7th Ed
- ANSYS 14.5 Design Exploration User Guide
- mgn-mqt82.exe
- Altium Designer 14 中文详细教程
- Altium Designer dblib简易制作教程
- 如何在 Altium Designer 中快速进行差分对
- 经典书籍Algorithms+Data Structures=Program
- [软件工程—实践者的研究方法].Roge
- Trojan-Qt5-Windows-0.0.4.rar
- Azure开发教程:Azure_Serverless_Computing
- Power Electronic Converters Modeling and Contr
- MySQL Notes For Professionals
- Remote Desktop Organizer v1.4.7 支持win10
- 酒店管理系统基于Qt Creator5)
- res10_300x300_ssd_iter_140000.caffemodel与dep
- umeshmotion网格推移
- 基于ACCESS的生产管理信息系统.mdb
- OpenGL参考手册
- ACCESS财务报表(带数据).accdb
-
st
yles 引文样式语言( CSL ) 引文样 - The direction of synaptic plasticity mediated
- Histamine excites rat lateral vestibular nucle
评论
共有 条评论