使用GLKit和OpenGL-ES,如何绘制两个三角形,一个带纹理,另一个实体 [英] Using GLKit and OpenGL-ES, How To Draw Two Triangles, One Textured, Another Solid

查看:207
本文介绍了使用GLKit和OpenGL-ES,如何绘制两个三角形,一个带纹理,另一个实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是OpenGL-ES的新手,已经开始通过Buck的学习适用于iOS的OpenGL ES 书.

I'm new to OpenGL-ES and have started working my way through Buck's Learning OpenGL ES for iOS book.

第2章介绍了用纯色绘制三角形,第3章继续使用纹理.

Chapter 2 covers drawing triangles with a solid color, and chapter 3 moves on to use textures.

作为个人学习练习,我试图更改示例代码以绘制两个三角形.一个带有纹理,另一个带有固体.

As a personal learning exercise, I'm trying to alter the sample code to draw two triangles; one with the texture, the other solid.

似乎是一项非常基本的练习,但作为OpenGL-ES初学者的 -证明是棘手的.

Seems like a very basic exercise, but one that - as an OpenGL-ES beginner - is proving tricky.

到目前为止,我已经尝试了多种方法.

So far I've tried a combination of things.

首先,我准备先绘制GLKVertexAttribPosition,然后再绘制GLKVertexAttribTexCoord0.然后,我用三角形1绘制顶点缓冲区.

First, I prepare to draw with GLKVertexAttribPosition, then GLKVertexAttribTexCoord0. I then draw my vertex buffer with triangle 1.

接下来,我尝试了几件事,包括:

Next, I've tried a couple of things, including:

    glDisableVertexAttribArray(GLKVertexAttribTexCoord0);

    GLuint name = self.textureInfo0.name;
    glDeleteTextures(1, &name);

然后绘制颜色属性:

[self.vertexBuffer prepareToDrawWithAttrib:GLKVertexAttribColor
                       numberOfCoordinates:3
                              attribOffset:offsetof(SceneVertex, colours)
                              shouldEnable:YES];

您可以在屏幕截图中看到,左下三角形的纹理与顶点颜色属性混合在一起.构成正方形的直角三角形是完全黑色的.

You can see in the screenshot that the bottom left triangle has the texture blended with the vertex color attributes. The right triangle - that makes the square - is completely black.

请注意,prepareToDrawWithAttrib方法调用是Buck的实用程序类,主要是调用glVertexAttribPointer方法.

Note that the prepareToDrawWithAttrib method calls are Buck's utility classes that principally call the glVertexAttribPointer method.

请务必注意,我使用的是

It's important to note that I'm using GLKit here, so no shaders or any of that stuff.

这是屏幕截图:

任何想法都值得赞赏.

推荐答案

我的建议之一是,如果您开始使用openGLES,请避免使用库(例如Buck的实用程序类).您必须清楚自己在做什么.不要浪费时间使用GLKBaseEffect.

One of my advice is to avoid library (like Buck's utility class) if you begin openGLES. You must know well what you're doing. Don't waste your time with GLKBaseEffect.

启动一个Xcode opengles项目.删除所有GLKBaseEffect部件并开始使用着色器,在进行简单照明时并不难.

Start an Xcode opengles project. Remove all the GLKBaseEffect part and start using shaders, it's not hard while you do simple lighting.

这篇关于使用GLKit和OpenGL-ES,如何绘制两个三角形,一个带纹理,另一个实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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