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

查看:167
本文介绍了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天全站免登陆