当前位置: 首页 > news >正文

怎么建网站 做app软件网页制作用什么软件做

怎么建网站 做app软件,网页制作用什么软件做,网站海报做一张多少钱,解决wordpress文件上传的大小限制纹理 在绘制三角形的过程中,将图片贴到三角形上进行显示的过程,就是纹理贴图的过程 uv坐标 如果如果图片尺寸和实际贴图尺寸不一致,就会导致像素不够用了的问题 纹理与采样 纹理对象(Texture):在GPU端,用来以一…

纹理

在绘制三角形的过程中,将图片贴到三角形上进行显示的过程,就是纹理贴图的过程在这里插入图片描述

uv坐标

如果如果图片尺寸和实际贴图尺寸不一致,就会导致像素不够用了的问题
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

纹理与采样

纹理对象(Texture):在GPU端,用来以一定格式存放纹理图片描述信息和数据信息的对象
采样器(Sampler):在GPU端,用来根据uv坐标以一定算法从纹理内容中获取颜色的过程称为采样,执行采样的对象为采样器
在这里插入图片描述
使用stbImage库(只需要头文件)读取图片

stbi_uc *stbi_load(char const *filename, int *x, int *y, int *comp, int req_comp)

filename:图片路径
x,y:图片宽度和高度
comp:读取图片本身的通道种类(RGP/RGBA/GREY)
req_comp:期望读出来的通道种类(RGP/RGBA/GREY)
在这里插入图片描述
读取出来的图片以左上方为原点,而opengl是左下方为原点,因此读取出来的图片必须反转y轴

stbi_set_flip_vertically_on_load(true);

上述代码即可将转换为opengl坐标

纹理单元

用于链接采样器(Sampler)和纹理对象(Texture),让Sampler知道去哪个纹理对象采样
在这里插入图片描述

创建纹理对象

在这里插入图片描述
在这里插入图片描述

纹理过滤

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

纹理包裹

当uv坐标超出了0-1范围,该怎么办

  • Repeat:重复纹理
  • Mirrored:镜像纹理
  • ClampToEdge:边缘复用
  • ClampToBorder:设置边缘颜色,且复用
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
#include <glad/glad.h>//glad必须在glfw头文件之前包含
#include <GLFW/glfw3.h>
#include <iostream>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
void frameBufferSizeCallbakc(GLFWwindow* window, int width, int height)
{glViewport(0, 0, width, height);
}
void glfwKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
}GLuint program = 0;
GLuint vao = 0;
GLuint texture = 0;
void prepareVAO()
{//positionsfloat positions[] = {-0.5f, -0.5f, 0.0f,0.5f, -0.5f, 0.0f,0.0f,  0.5f, 0.0f,};//颜色float colors[] = {1.0f, 0.0f,0.0f,0.0f, 1.0f,0.0f,0.0f, 0.0f,1.0f};//索引unsigned int indices[] = {0, 1, 2,};//uv坐标float uvs[] = {0.0f, 0.0f,1.0f, 0.0f,0.5f, 1.0f,};//2 VBO创建GLuint posVbo = 0;GLuint colorVbo = 0;GLuint uvVbo = 0;glGenBuffers(1, &posVbo);glBindBuffer(GL_ARRAY_BUFFER, posVbo);glBufferData(GL_ARRAY_BUFFER, sizeof(positions), positions, GL_STATIC_DRAW);glGenBuffers(1, &colorVbo);glBindBuffer(GL_ARRAY_BUFFER, colorVbo);glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW);glGenBuffers(1, &uvVbo);glBindBuffer(GL_ARRAY_BUFFER, uvVbo);glBufferData(GL_ARRAY_BUFFER, sizeof(uvs), uvs, GL_STATIC_DRAW);//3 EBO创建GLuint ebo = 0;glGenBuffers(1, &ebo);glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);//4 VAO创建vao = 0;glGenVertexArrays(1, &vao);glBindVertexArray(vao);//5 绑定vbo ebo 加入属性描述信息//5.1 加入位置属性描述信息glBindBuffer(GL_ARRAY_BUFFER, posVbo);glEnableVertexAttribArray(0);glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);//5.2 加入颜色属性描述信息glBindBuffer(GL_ARRAY_BUFFER, colorVbo);glEnableVertexAttribArray(1);glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);//5.3 加入uv属性描述数据glBindBuffer(GL_ARRAY_BUFFER, uvVbo);glEnableVertexAttribArray(2);glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)0);//5.2 加入ebo到当前的vaoglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);glBindVertexArray(0);
}
void prepareShader() {//1 完成vs与fs的源代码,并且装入字符串const char* vertexShaderSource ="#version 330 core\n""layout (location = 0) in vec3 aPos;\n""layout (location = 1) in vec3 aColor;\n""layout (location = 2) in vec2 aUV;\n""out vec3 color;\n""out vec2 uv;\n""void main()\n""{\n""   gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n""   color = aColor;\n""   uv = aUV;\n""}\0";const char* fragmentShaderSource ="#version 330 core\n""out vec4 FragColor;\n""in vec3 color;\n""in vec2 uv;\n""uniform sampler2D sampler;\n""void main()\n""{\n""   FragColor = texture(sampler, uv);\n""}\n\0";//2 创建Shader程序(vs、fs)GLuint vertex, fragment;vertex = glCreateShader(GL_VERTEX_SHADER);fragment = glCreateShader(GL_FRAGMENT_SHADER);//3 为shader程序输入shader代码glShaderSource(vertex, 1, &vertexShaderSource, NULL);glShaderSource(fragment, 1, &fragmentShaderSource, NULL);int success = 0;char infoLog[1024];//4 执行shader代码编译 glCompileShader(vertex);//检查vertex编译结果glGetShaderiv(vertex, GL_COMPILE_STATUS, &success);if (!success) {glGetShaderInfoLog(vertex, 1024, NULL, infoLog);std::cout << "Error: SHADER COMPILE ERROR --VERTEX" << "\n" << infoLog << std::endl;}glCompileShader(fragment);//检查fragment编译结果glGetShaderiv(fragment, GL_COMPILE_STATUS, &success);if (!success) {glGetShaderInfoLog(fragment, 1024, NULL, infoLog);std::cout << "Error: SHADER COMPILE ERROR --FRAGMENT" << "\n" << infoLog << std::endl;}//5 创建一个Program壳子program = glCreateProgram();//6 将vs与fs编译好的结果放到program这个壳子里glAttachShader(program, vertex);glAttachShader(program, fragment);//7 执行program的链接操作,形成最终可执行shader程序glLinkProgram(program);//检查链接错误glGetProgramiv(program, GL_LINK_STATUS, &success);if (!success) {glGetProgramInfoLog(program, 1024, NULL, infoLog);std::cout << "Error: SHADER LINK ERROR " << "\n" << infoLog << std::endl;}//清理glDeleteShader(vertex);glDeleteShader(fragment);
}void prepareTextrue()
{//1 stbImage 读取图片int width, height, channels;//--反转y轴stbi_set_flip_vertically_on_load(true);unsigned char* data = stbi_load("goku.jpg", &width, &height, &channels, STBI_rgb_alpha);//2 生成纹理并且激活单元绑定glGenTextures(1, &texture);//--激活纹理单元--glActiveTexture(GL_TEXTURE0);//--绑定纹理对象--glBindTexture(GL_TEXTURE_2D, texture);//3 传输纹理数据,开辟显存glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);//***释放数据stbi_image_free(data);//4 设置纹理的过滤方式glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);//5 设置纹理的包裹方式glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);//uglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);//v
}void render()
{//执行opengl画布清理操作glClear(GL_COLOR_BUFFER_BIT);//1.绑定当前的programglUseProgram(program);//2 更新Uniform的时候,一定要先UserProgram//2.1 通过名称拿到Uniform变量的位置LocationGLint location = glGetUniformLocation(program, "sampler");//2.2 通过Location更新Uniform变量的值glUniform1f(location, 0);//3 绑定当前的vaoglBindVertexArray(vao);//4 发出绘制指令//glDrawArrays(GL_TRIANGLE_STRIP, 0, 6);glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0);
}int main()
{//初始化glfw环境glfwInit();//设置opengl主版本号glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);//设置opengl次版本号glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);//设置opengl启用核心模式glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);//创建窗体对象GLFWwindow* window = glfwCreateWindow(800, 600, "lenarnOpenGL", nullptr, nullptr);//设置当前窗体对象为opengl的绘制舞台glfwMakeContextCurrent(window);//窗体大小回调glfwSetFramebufferSizeCallback(window, frameBufferSizeCallbakc);//键盘相应回调glfwSetKeyCallback(window, glfwKeyCallback);//使用glad加载所有当前版本opengl的函数if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)){std::cout << "初始化glad失败" << std::endl;return -1;};//设置opengl视口大小和清理颜色glViewport(0, 0, 800, 600);glClearColor(0.2f, 0.3f, 0.3f, 1.0f);//shaderprepareShader();//vaoprepareVAO();//textureprepareTextrue();//执行窗体循环while (!glfwWindowShouldClose(window)){//接受并分发窗体消息//检查消息队列是否有需要处理的鼠标、键盘等消息//如果有的话就将消息批量处理,清空队列glfwPollEvents();//渲染操作render();//切换双缓存glfwSwapBuffers(window);}//推出程序前做相关清理glfwTerminate();return 0;
}

在这里插入图片描述
上面这个例子中,成功的将一张图片绘制到了三角形中。
在vao中加入uv坐标描述信息,vs中读取vao中的uv信息传递给fs,fs中加入采样器uniform变量,在渲染时设置采样器的值和采样单元值一致即可。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述


文章转载自:
http://dinncodemographer.bkqw.cn
http://dinncoheadcheese.bkqw.cn
http://dinncotetrastichous.bkqw.cn
http://dinncorhonda.bkqw.cn
http://dinncoconnective.bkqw.cn
http://dinncograser.bkqw.cn
http://dinncolibertyman.bkqw.cn
http://dinncohelvetii.bkqw.cn
http://dinncobritannic.bkqw.cn
http://dinncozinkite.bkqw.cn
http://dinncoantiparallel.bkqw.cn
http://dinncojackfield.bkqw.cn
http://dinncoparlous.bkqw.cn
http://dinncopennywort.bkqw.cn
http://dinncofortuneteller.bkqw.cn
http://dinncopresage.bkqw.cn
http://dinncoborghese.bkqw.cn
http://dinncogrievous.bkqw.cn
http://dinncodomesticate.bkqw.cn
http://dinncowindtight.bkqw.cn
http://dinncojacobin.bkqw.cn
http://dinncodaze.bkqw.cn
http://dinncoinworks.bkqw.cn
http://dinncochristiania.bkqw.cn
http://dinncooilcan.bkqw.cn
http://dinncoakos.bkqw.cn
http://dinncoplaguy.bkqw.cn
http://dinncoairglow.bkqw.cn
http://dinncoradical.bkqw.cn
http://dinncointerfile.bkqw.cn
http://dinncomaris.bkqw.cn
http://dinncocryptanalyze.bkqw.cn
http://dinncodune.bkqw.cn
http://dinncohierurgy.bkqw.cn
http://dinncohominoid.bkqw.cn
http://dinncodeclassee.bkqw.cn
http://dinncosplicer.bkqw.cn
http://dinncoobsequious.bkqw.cn
http://dinncolinter.bkqw.cn
http://dinncodogmatician.bkqw.cn
http://dinncocit.bkqw.cn
http://dinncoromanticism.bkqw.cn
http://dinncobilbao.bkqw.cn
http://dinncokantar.bkqw.cn
http://dinncoqr.bkqw.cn
http://dinncodispermous.bkqw.cn
http://dinncobluepencil.bkqw.cn
http://dinncocarbonous.bkqw.cn
http://dinncolibation.bkqw.cn
http://dinncoethmoid.bkqw.cn
http://dinncoornithine.bkqw.cn
http://dinncoanapurna.bkqw.cn
http://dinnconeorealist.bkqw.cn
http://dinncooffbeat.bkqw.cn
http://dinncosuperrat.bkqw.cn
http://dinncowhiz.bkqw.cn
http://dinncohoropter.bkqw.cn
http://dinncohestia.bkqw.cn
http://dinncooophore.bkqw.cn
http://dinncowdp.bkqw.cn
http://dinncorepulse.bkqw.cn
http://dinncoassailment.bkqw.cn
http://dinncocollaret.bkqw.cn
http://dinncoinqilab.bkqw.cn
http://dinncocornmeal.bkqw.cn
http://dinncoslipstream.bkqw.cn
http://dinncononcellulosic.bkqw.cn
http://dinncoyahveh.bkqw.cn
http://dinncocoactive.bkqw.cn
http://dinncounhidden.bkqw.cn
http://dinncooverrespond.bkqw.cn
http://dinncosansculotterie.bkqw.cn
http://dinncotraitorously.bkqw.cn
http://dinncocobalt.bkqw.cn
http://dinncoadjunct.bkqw.cn
http://dinncojessamine.bkqw.cn
http://dinncocommerciogenic.bkqw.cn
http://dinncolachrymose.bkqw.cn
http://dinncofescue.bkqw.cn
http://dinncoaerosiderolite.bkqw.cn
http://dinncoaerophobe.bkqw.cn
http://dinncochignon.bkqw.cn
http://dinncotehran.bkqw.cn
http://dinncodaybill.bkqw.cn
http://dinncosublibrarian.bkqw.cn
http://dinncocleverish.bkqw.cn
http://dinncorepeal.bkqw.cn
http://dinncoharbinger.bkqw.cn
http://dinncozonate.bkqw.cn
http://dinncoorthographical.bkqw.cn
http://dinncoitself.bkqw.cn
http://dinncohilary.bkqw.cn
http://dinncoapian.bkqw.cn
http://dinncoconstitution.bkqw.cn
http://dinncolustra.bkqw.cn
http://dinncointegrand.bkqw.cn
http://dinncomicrocosmos.bkqw.cn
http://dinncoobdr.bkqw.cn
http://dinncowiglet.bkqw.cn
http://dinncocaulomic.bkqw.cn
http://www.dinnco.com/news/133616.html

相关文章:

  • ps网站子页怎么做百度网站安全检测
  • 美女做羞羞的视频网站子域名查询工具
  • 北京做网站公司推荐seo单词优化
  • 网站目录管理模板下载seo初学教程
  • 有好点的做网站的公司吗如何在百度上做广告宣传
  • 郑州网络优化实力乐云seo上海做网络口碑优化的公司
  • 做机票在线预订网站近期的新闻消息
  • 自己做家具网站百度app登录
  • 什么叫互联网seo搜索引擎优化人员
  • 正能量网站有哪些小说网站排名前十
  • 郑州网站制作公司排名微商推广哪家好
  • 学网站开发需要会什么seo搜索培训
  • 哈尔滨开发网站重庆百度推广电话
  • 深圳网页设计培训学校上海关键词优化排名软件
  • asp网站首页模板新闻源软文发布平台
  • 软件工程月薪一般多少新泰网站seo
  • 成都网站建设公司排行如何做好网络营销推广
  • 重庆分类健康管理优化王
  • 最早做弹幕的网站搜狗seo刷排名软件
  • 网站优化策略湖南seo推广多少钱
  • 建设政府网站的流程北京seo顾问推推蛙
  • wordpress博客增加音乐页面seo站长网怎么下载
  • 番禺网站制作设计网络公司网络营销推广方案
  • 做两个阿里网站网站推广120种方法
  • php 移动网站开发口碑营销的形式
  • 营销型网站建设的原则电商营销策划方案
  • 网站开发费入账windows优化大师下载安装
  • 网站建设有掏钱么怎样把广告放到百度
  • 广州申请公司注册网站南宁百度seo排名优化
  • 手机网站用什么软件做b站2023推广网站