OpenGL ES 2.0 使用纹理渲染 [英] OpenGL ES 2.0 Rendering with a Texture

查看:29
本文介绍了OpenGL ES 2.0 使用纹理渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iPhone SDK 有一个使用 ES 2.0 和一组(顶点和片段)GLSL 着色器来渲染不同颜色的框的示例.是否有关于如何使用此 API 呈现简单纹理的示例?我基本上想取一个四边形,并在其上绘制纹理.

The iPhone SDK has an example of using ES 2.0 with a set of (Vertex & Fragment) GLSL shaders to render a varying colored box. Is there an example out there on how to render a simple texture using this API? I basically want to take a quad, and draw a texture onto it.

旧的 ES 1.1 API 根本不再工作,所以我需要一些帮助才能开始.大多数着色器参考主要讨论高级着色主题,但我真的不确定如何告诉着色器使用绑定的纹理,以及如何引用 UV.

The old ES 1.1 API's don't work at all anymore, so I'm needing a bit of help getting started. Most shader references talk mainly about advanced shading topics, but I'm really unsure about how to tell the shader to use the bound texture, and how to reference the UV's.

推荐答案

在网站上有一个很好的教程可以和本书一起使用 OpenGL ES 2 书中的例子都在 www.opengles-book.com.

There's a nice tutorial on this in the web site to go with the book OpenGL ES 2 The examples from the book are all at www.opengles-book.com.

第 9 章,Simple_Texture2D 完全符合您的要求.它设置了一个着色器,对纹理进行采样、初始化并使用纹理对三角形进行着色.

Chapter 9, Simple_Texture2D does exactly what you want. It sets up a shader that samples a texture, initializes it, and shades the triangles using the texture.

着色器程序接近:

varying vec2 v_texCoord;
uniform sampler2D s_texture;
void main() {
  gl_FragColor = texture2D(s_texture, v_texCoord);
}

然后你就这样设置了:

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, userData->textureId);
// Set the sampler texture unit to 0
glUniform1i(userData->samplerLoc, 0);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);

但是从我上面给出的链接中查看实际代码,才能真正看到示例.

But see the actual code, from the links I gave above, to really see the example.

这篇关于OpenGL ES 2.0 使用纹理渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆