- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我完全没有想法。
我有 OpenGL ES 2.0 编程指南书,我有 Apple 的模板 OpenGL ES 2.0 代码,我已关注此页面:http://open.gl/drawing
我似乎无法绘制一个简单的三角形,我不确定我做错了什么。
注意:我也有一个 GameViewController.xib 文件,它是 GLKView 的子类,就像 Apple 的模板代码一样。
我的顶点着色器:
attribute vec4 position;
void main()
{
gl_Position = position;
}
我的片段着色器:
void main()
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
我的 GameViewController 头文件:
#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>
@interface GameViewController : GLKViewController
@end
我的 GameViewController 实现文件:
#import "GameViewController.h"
const GLfloat vertices[] =
{
0.0f, 0.5f,
-0.5f, -0.5f,
0.5f, -0.5f
};
// Class extension to keep data private
@interface GameViewController()
{
// vertex buffer object
GLuint vbo;
// vertex array object
GLuint vao;
// shader program
GLuint shaderProgram;
}
@property (strong, nonatomic) EAGLContext *context;
@property (strong, nonatomic) GLKBaseEffect *effect;
@end
@implementation GameViewController
// setup our OpenGL context
-(void)viewDidLoad
{
[super viewDidLoad];
[self setupContext];
// -------------------------------------------------------------
// create a vertex array object that will hold
// all the linking between attributes and vertex data
// -------------------------------------------------------------
[self createVertexArrayObject];
[self createVertexBufferObject];
[self loadShaders];
[self checkErrors];
}
-(void)checkErrors
{
GLenum error = glGetError();
switch (error) {
case GL_NO_ERROR:
NSLog(@"No errors");
break;
case GL_INVALID_ENUM:
NSLog(@"An unacceptable value is specified for an enumerated argument. The offending command is ignored and has no other side effect than to set the error flag.");
break;
case GL_INVALID_VALUE:
NSLog(@"A numeric argument is out of range. The offending command is ignored and has no other side effect than to set the error flag.");
break;
case GL_INVALID_OPERATION:
NSLog(@"The specified operation is not allowed in the current state. The offending command is ignored and has no other side effect than to set the error flag.");
break;
case GL_INVALID_FRAMEBUFFER_OPERATION:
NSLog(@"The frameBuffer object is not complete. The offending command is ignored and has no other side effect than to set the error flag.");
break;
case GL_OUT_OF_MEMORY:
NSLog(@"There is not enough memory left to execute the command. The state of the GL is undefined, except for the state of the error flags, after this error is recorded.");
break;
case GL_STACK_UNDERFLOW:
NSLog(@"An attempt has been made to perform an operation that would cause an internal stack to underflow.");
break;
case GL_STACK_OVERFLOW:
NSLog(@"An attempt has been made to perform an operation that would cause an internal stack to overflow.");
break;
default:
break;
}
}
#pragma mark - Setup Context -
-(void)setupContext
{
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if(!self.context)
{
NSLog(@"Failed to create OpenGL ES Context");
}
// tell our view the context is an OpenGL context
GLKView *view = (GLKView *)self.view;
view.context = self.context;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
[EAGLContext setCurrentContext:self.context];
self.effect = [[GLKBaseEffect alloc] init];
glEnable(GL_DEPTH_TEST);
}
#pragma mark - Vertex Array Object Methods -
-(void)createVertexArrayObject
{
glGenVertexArraysOES(1, &vao);
glBindVertexArrayOES(vao);
}
#pragma mark - Create Vertex Buffer Object Method -
-(void)createVertexBufferObject;
{
glGenBuffers(1, &vbo); // Generate 1 memory buffer for the VBO
// Make our VBO the current buffer object to receive data
glBindBuffer(GL_ARRAY_BUFFER, vbo);
// -------------------------------------------------------------
// Start copying data to our VBO
//
// GL_STATIC_DRAW will upload once and drawn many times
// -------------------------------------------------------------
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
}
#pragma mark - Shader Code -
-(void)loadShaders
{
// load both vertex shader and fragment shader
GLuint vertexShader = [self compileVertexShader];
GLuint fragmentShader = [self compileFragmentShader];
// create a shader program from the vertex shader and fragment shader
shaderProgram = [self combineVertexShader:vertexShader AndFragmentShader:fragmentShader];
// linking vertex data and attributes
GLint positionAttrib = glGetAttribLocation(shaderProgram, "position");
glVertexAttribPointer(positionAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(positionAttrib);
}
-(GLuint)compileVertexShader
{
// get the path to the shader file as a C string
const GLchar *vertexShaderPath = (GLchar *)[[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Shader" ofType:@"vsh"]
encoding:NSUTF8StringEncoding
error:nil] UTF8String];
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vertexShaderPath, NULL);
glCompileShader(vertexShader);
// Checking if shader compiled properly
GLint status;
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &status);
if(status == GL_TRUE)
{
NSLog(@"Vertex shader compiled correctly");
}
else
{
NSLog(@"Vertex shader compiled failed");
}
GLint logLength;
glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0) {
GLchar *log = (GLchar *)malloc(logLength);
glGetShaderInfoLog(vertexShader, logLength, &logLength, log);
NSLog(@"Vertex Shader compile log:\n%s", log);
free(log);
}
return vertexShader;
}
-(GLuint)compileFragmentShader
{
// get the path to the shader as a C string
const GLchar *fragmentShaderPath = (GLchar *)[[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Shader" ofType:@"fsh"]
encoding:NSUTF8StringEncoding
error:nil] UTF8String];
GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &fragmentShaderPath, NULL);
glCompileShader(fragmentShader);
// Checking if shader compiled properly
GLint status;
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &status);
if(status == GL_TRUE)
{
NSLog(@"Fragment shader compiled correctly");
}
else
{
NSLog(@"Fragment shader compiled failed");
}
GLint logLength;
glGetShaderiv(fragmentShader, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0) {
GLchar *log = (GLchar *)malloc(logLength);
glGetShaderInfoLog(fragmentShader, logLength, &logLength, log);
NSLog(@"Fragment Shader compile log:\n%s", log);
free(log);
}
return fragmentShader;
}
-(void)linkProgram:(GLuint)paramShaderProgram
{
// link shader to program now and become active shader program
glLinkProgram(paramShaderProgram);
GLint status;
// test if the program linked correctly
glGetProgramiv(paramShaderProgram, GL_LINK_STATUS, &status);
if(status == GL_TRUE)
{
NSLog(@"Shader program linked correctly");
}
else
{
NSLog(@"Shader program linked failed");
}
}
-(void)validateProgram:(GLuint)paramShaderProgram
{
GLint status, logLength;
glValidateProgram(paramShaderProgram);
glGetProgramiv(paramShaderProgram, GL_VALIDATE_STATUS, &status);
if(status == GL_TRUE)
{
NSLog(@"Shader program validated correctly");
}
else
{
NSLog(@"Shader program validate failed");
}
glGetProgramiv(paramShaderProgram, GL_INFO_LOG_LENGTH, &logLength);
if(logLength > 0)
{
GLchar *log = (GLchar *)malloc(logLength);
glGetProgramInfoLog(paramShaderProgram, logLength, &logLength, log);
NSLog(@"Program validate log:\n%s", log);
free(log);
}
}
-(GLuint)combineVertexShader:(GLuint)paramVertexShader AndFragmentShader:(GLuint)paramFragmentShader
{
GLuint newShaderProgram = glCreateProgram();
glAttachShader(newShaderProgram, paramVertexShader);
glAttachShader(newShaderProgram, paramFragmentShader);
[self linkProgram:newShaderProgram];
[self validateProgram:newShaderProgram];
// start using shader now, will use the active shader program
glUseProgram(newShaderProgram);
return newShaderProgram;
}
#pragma mark - GLKViewController Render Delegate Methods -
-(void)setupViewport
{
glViewport(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
self.effect.transform.projectionMatrix = GLKMatrix4MakeOrtho(-3, 3, -2, 2, 1, -1);
}
-(void)update
{
[self setupViewport];
}
-(void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
glClearColor(0.65f, 0.65f, 0.65f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
[self.effect prepareToDraw];
glDrawArrays(GL_TRIANGLES, 0, 3);
}
#pragma mark - Cleanup Memory -
-(void)tearDownContext
{
[EAGLContext setCurrentContext:self.context];
// delete vertex buffer object and vertex array object
glDeleteBuffers(1, &vbo);
glDeleteVertexArraysOES(1, &vao);
// delete shader program
if(shaderProgram)
{
glDeleteProgram(shaderProgram);
shaderProgram = 0;
}
// unset OpenGL context
if ([EAGLContext currentContext] == self.context)
{
[EAGLContext setCurrentContext:nil];
}
self.context = nil;
}
-(void)dealloc
{
[self tearDownContext];
}
-(void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
if([self isViewLoaded] && self.view.window == nil)
{
self.view = nil;
[self tearDownContext];
if([EAGLContext currentContext] == self.context)
{
[EAGLContext setCurrentContext:nil];
}
self.context = nil;
}
// Dispose of any resources that can be recreated
}
@end
我所看到的只是我清除颜色后的灰色背景屏幕。
如果有人能指出我哪里做错了,那就太好了。
我决定抛开个人对 Ray 网站的厌恶,硬着头皮完成本教程:
http://www.raywenderlich.com/3664/opengl-es-2-0-for-iphone-tutorial
本教程不使用 GLKit,这是一个额外的好处,因为学习者编写自己的帧缓冲区和渲染缓冲区,并将它们呈现在屏幕上。
我觉得这比使用 GLKit 更接近 OpenGL ES 2.0 管道。
正如 Ricardo 所建议的那样,在这个时间点上使用 GLKit 比理解它的值(value)要付出更多的努力。
我还强烈建议使用上面 Ray 的网站教程链接来运行一个工作程序,而不是尝试遵循 Apple 的模板代码。
就我而言,苹果的模板代码和书上有太多的矛盾,造成了很多时间的浪费。
对于那些仍然对使用 GLKit 方法感兴趣的人,我还使用 GLKit 解决了这个问题。
解决方案是结合设置我的投影矩阵和绑定(bind)正确的顶点着色器位置属性位置。
我还想指出一个非常重要的注意事项是:
确保目标的复制捆绑资源具有顶点和片段着色器!
我正处于三角形为黑色的位置,无论我在片段着色器文件中键入什么,我都无法更改三角形的颜色。问题是默认情况下这些着色器文件不会复制到包资源。
无论如何,下面完整地提供了我的工作更新代码:
#import "GameViewController.h"
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
// Uniform index.
enum
{
UNIFORM_MODELVIEWPROJECTION_MATRIX,
UNIFORM_NORMAL_MATRIX,
NUM_UNIFORMS
};
GLint uniforms[NUM_UNIFORMS];
// Attribute index.
enum
{
ATTRIB_VERTEX,
ATTRIB_NORMAL,
NUM_ATTRIBUTES
};
const GLfloat vertices[] =
{
0.0f, 0.5f,
-0.5f, -0.5f,
0.5f, -0.5f
};
// Class extension to keep data private
@interface GameViewController()
{
// vertex buffer object
GLuint vbo;
// vertex array object
GLuint vao;
// shader program
GLuint shaderProgram;
GLKMatrix4 modelViewProjectionMatrix;
GLKMatrix3 normalMatrix;
}
@property (strong, nonatomic) EAGLContext *context;
@property (strong, nonatomic) GLKBaseEffect *effect;
@end
@implementation GameViewController
// setup our OpenGL context
-(void)viewDidLoad
{
[super viewDidLoad];
[self setupContext];
[self loadShaders];
// -------------------------------------------------------------
// create a vertex array object that will hold
// all the linking between attributes and vertex data
// -------------------------------------------------------------
[self createVertexArrayObject];
[self createVertexBufferObject];
[self linkAttributes];
[self checkErrors];
}
-(void)checkErrors
{
GLenum error = glGetError();
switch (error) {
case GL_NO_ERROR:
NSLog(@"No errors");
break;
case GL_INVALID_ENUM:
NSLog(@"An unacceptable value is specified for an enumerated argument. The offending command is ignored and has no other side effect than to set the error flag.");
break;
case GL_INVALID_VALUE:
NSLog(@"A numeric argument is out of range. The offending command is ignored and has no other side effect than to set the error flag.");
break;
case GL_INVALID_OPERATION:
NSLog(@"The specified operation is not allowed in the current state. The offending command is ignored and has no other side effect than to set the error flag.");
break;
case GL_INVALID_FRAMEBUFFER_OPERATION:
NSLog(@"The frameBuffer object is not complete. The offending command is ignored and has no other side effect than to set the error flag.");
break;
case GL_OUT_OF_MEMORY:
NSLog(@"There is not enough memory left to execute the command. The state of the GL is undefined, except for the state of the error flags, after this error is recorded.");
break;
case GL_STACK_UNDERFLOW:
NSLog(@"An attempt has been made to perform an operation that would cause an internal stack to underflow.");
break;
case GL_STACK_OVERFLOW:
NSLog(@"An attempt has been made to perform an operation that would cause an internal stack to overflow.");
break;
default:
break;
}
}
#pragma mark - Setup Context -
-(void)setupContext
{
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if(!self.context)
{
NSLog(@"Failed to create OpenGL ES Context");
}
// tell our view the context is an OpenGL context
GLKView *view = (GLKView *)self.view;
view.context = self.context;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
[EAGLContext setCurrentContext:self.context];
self.effect = [[GLKBaseEffect alloc] init];
//glEnable(GL_DEPTH_TEST);
}
#pragma mark - Vertex Array Object Methods -
-(void)createVertexArrayObject
{
glGenVertexArraysOES(1, &vao);
glBindVertexArrayOES(vao);
}
#pragma mark - Create Vertex Buffer Object Method -
-(void)createVertexBufferObject;
{
glGenBuffers(1, &vbo); // Generate 1 memory buffer for the VBO
// Make our VBO the current buffer object to receive data
glBindBuffer(GL_ARRAY_BUFFER, vbo);
// -------------------------------------------------------------
// Start copying data to our VBO
//
// GL_STATIC_DRAW will upload once and drawn many times
// -------------------------------------------------------------
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
}
-(void)linkAttributes
{
/*
// linking vertex data and attributes
GLint positionAttrib = glGetAttribLocation(shaderProgram, "position");
glVertexAttribPointer(positionAttrib, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
glEnableVertexAttribArray(positionAttrib);
*/
glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
glEnableVertexAttribArray(GLKVertexAttribPosition);
glBindVertexArrayOES(0);
}
#pragma mark - Shader Code -
-(void)loadShaders
{
shaderProgram = glCreateProgram();
// load both vertex shader and fragment shader
GLuint vertexShader = [self compileVertexShader];
GLuint fragmentShader = [self compileFragmentShader];
// create a shader program from the vertex shader and fragment shader
[self combineVertexShader:vertexShader AndFragmentShader:fragmentShader];
[self linkProgram:shaderProgram];
// Release vertex and fragment shaders.
if (vertexShader) {
glDetachShader(shaderProgram, vertexShader);
glDeleteShader(vertexShader);
}
if (fragmentShader) {
glDetachShader(shaderProgram, fragmentShader);
glDeleteShader(fragmentShader);
}
//NSLog(@"uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX] before = %d", uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX]);
uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX] = glGetUniformLocation(shaderProgram, "modelViewProjectionMatrix");
//NSLog(@"uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX] after = %d", uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX]);
}
-(GLuint)compileVertexShader
{
// get the path to the shader file as a C string
const GLchar *vertexShaderPath = (GLchar *)[[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Shader" ofType:@"vsh"]
encoding:NSUTF8StringEncoding
error:nil] UTF8String];
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vertexShaderPath, NULL);
glCompileShader(vertexShader);
// Checking if shader compiled properly
GLint status;
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &status);
if(status == GL_TRUE)
{
NSLog(@"Vertex shader compiled correctly");
}
else
{
NSLog(@"Vertex shader compiled failed");
}
GLint logLength;
glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0) {
GLchar *log = (GLchar *)malloc(logLength);
glGetShaderInfoLog(vertexShader, logLength, &logLength, log);
NSLog(@"Vertex Shader compile log:\n%s", log);
free(log);
}
return vertexShader;
}
-(GLuint)compileFragmentShader
{
// get the path to the shader as a C string
const GLchar *fragmentShaderPath = (GLchar *)[[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Shader" ofType:@"fsh"]
encoding:NSUTF8StringEncoding
error:nil] UTF8String];
GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &fragmentShaderPath, NULL);
glCompileShader(fragmentShader);
// Checking if shader compiled properly
GLint status;
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &status);
if(status == GL_TRUE)
{
NSLog(@"Fragment shader compiled correctly");
}
else
{
NSLog(@"Fragment shader compiled failed");
}
GLint logLength;
glGetShaderiv(fragmentShader, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0) {
GLchar *log = (GLchar *)malloc(logLength);
glGetShaderInfoLog(fragmentShader, logLength, &logLength, log);
NSLog(@"Fragment Shader compile log:\n%s", log);
free(log);
}
return fragmentShader;
}
-(void)combineVertexShader:(GLuint)paramVertexShader AndFragmentShader:(GLuint)paramFragmentShader
{
glAttachShader(shaderProgram, paramVertexShader);
glAttachShader(shaderProgram, paramFragmentShader);
glBindAttribLocation(shaderProgram, GLKVertexAttribPosition, "position");
//[self validateProgram:shaderProgram];
}
-(void)linkProgram:(GLuint)paramShaderProgram
{
// link shader to program now and become active shader program
glLinkProgram(paramShaderProgram);
GLint status;
// test if the program linked correctly
glGetProgramiv(paramShaderProgram, GL_LINK_STATUS, &status);
if(status == GL_TRUE)
{
NSLog(@"Shader program linked correctly");
}
else
{
NSLog(@"Shader program linked failed");
}
GLint logLength;
glGetProgramiv(shaderProgram, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0) {
GLchar *log = (GLchar *)malloc(logLength);
glGetProgramInfoLog(shaderProgram, logLength, &logLength, log);
NSLog(@"Program link log:\n%s", log);
free(log);
}
}
-(void)validateProgram:(GLuint)paramShaderProgram
{
GLint status, logLength;
glValidateProgram(paramShaderProgram);
glGetProgramiv(paramShaderProgram, GL_VALIDATE_STATUS, &status);
if(status == GL_TRUE)
{
NSLog(@"Shader program validated correctly");
}
else
{
NSLog(@"Shader program validate failed");
}
glGetProgramiv(paramShaderProgram, GL_INFO_LOG_LENGTH, &logLength);
if(logLength > 0)
{
GLchar *log = (GLchar *)malloc(logLength);
glGetProgramInfoLog(paramShaderProgram, logLength, &logLength, log);
NSLog(@"Program validate log:\n%s", log);
free(log);
}
}
#pragma mark - GLKViewController Render Delegate Methods -
-(void)setupViewport
{
//float aspect = fabsf(self.view.bounds.size.width / self.view.bounds.size.height);
//GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65.0f), aspect, 1.0f, -10.0f);
GLKMatrix4 projectionMatrix = GLKMatrix4MakeOrtho(-1, 1, -1, 1, 1, -1);
self.effect.transform.projectionMatrix = projectionMatrix;
GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, 0.0f);
self.effect.transform.modelviewMatrix = modelViewMatrix;
modelViewProjectionMatrix = GLKMatrix4Multiply(projectionMatrix, modelViewMatrix);
normalMatrix = GLKMatrix3InvertAndTranspose(GLKMatrix4GetMatrix3(modelViewMatrix), NULL);
glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX], 1, GL_FALSE, modelViewProjectionMatrix.m);
glUniformMatrix3fv(uniforms[UNIFORM_NORMAL_MATRIX], 1, 0, normalMatrix.m);
}
-(void)update
{
[self setupViewport];
}
-(void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
glClearColor(0.65f, 0.65f, 0.65f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glBindVertexArrayOES(vao);
[self.effect prepareToDraw];
glUseProgram(shaderProgram);
glDrawArrays(GL_TRIANGLES, 0, 3);
}
#pragma mark - Cleanup Memory -
-(void)tearDownContext
{
[EAGLContext setCurrentContext:self.context];
// delete vertex buffer object and vertex array object
glDeleteBuffers(1, &vbo);
glDeleteVertexArraysOES(1, &vao);
// delete shader program
if(shaderProgram)
{
glDeleteProgram(shaderProgram);
shaderProgram = 0;
}
// unset OpenGL context
if ([EAGLContext currentContext] == self.context)
{
[EAGLContext setCurrentContext:nil];
}
self.context = nil;
}
-(void)dealloc
{
[self tearDownContext];
}
-(void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
if([self isViewLoaded] && self.view.window == nil)
{
self.view = nil;
[self tearDownContext];
if([EAGLContext currentContext] == self.context)
{
[EAGLContext setCurrentContext:nil];
}
self.context = nil;
}
// Dispose of any resources that can be recreated
}
@end
希望对其他人有所帮助。
最佳答案
忘记 Apple 的 OpenGL ES 2.0 模板代码吧。如果您是初学者,那么其中有太多内容无法正确理解,而且它混合了 OpenGL ES 1.1 (GLKBaseEffect) 和 2.0(着色器)。
您最好从头开始创建应用并了解 GLKit 和着色器的优缺点。
本教程使用 GLKBaseEffect 的固定管道功能对 GLKit 进行了很好的介绍:
如果您想更深入地了解并学习如何在 iPhone 环境中使用着色器,我强烈推荐这本书:
最终,您可能希望结合使用 GLKView 来绕过所有缓冲区样板代码,并使用着色器来最好地控制您的程序。OpenGL ES 有一个艰难的学习曲线,但一旦你克服了第一个障碍,事情就会变得更加清晰。
关于ios - OpenGL ES 2.0 绘制不显示任何内容的简单三角形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14012780/
在 settings.py LANGUAGE_CODE = 'es-mx'或 LANGUAGE_CODE = 'es-ar'不起作用,但是 LANGUAGE_CODE = 'es'或 LANGUAGE
我想知道OpenGL ES 2.0和OpenGL ES 3.0之间有什么区别。 OpenGL ES 3.0的主要优点是什么? 最佳答案 总体而言,这些变化通过更大的缓冲区、更多的格式、更多的统一等提高
这是我为此端点使用 Postman localhost:9201/response_v2_862875ee3a88a6d09c95bdbda029ce2b/_search 的请求正文 { "_sour
OpenGL ES 2.0 没有 ES 1.0 那样的 GL_POINT_SMOOTH 定义。这意味着我用来绘制圆圈的代码不再有效: glEnable(GL_POINT_SMOOTH); glPoin
我尝试编译这个着色器: varying vec2 TexCoords; varying vec4 color; uniform sampler2D text; uniform vec3 textCol
我是 OpenGL ES 的新手,我使用的是 OpenGL ES 2.0 版本。我可以在片段着色器中使用按位操作(右移、左移)吗? 最佳答案 OpenGL ES 2.0 没有按位运算符。 ES 3.0
有没有办法只用线画一个三角形? 我认为GL_TRIANGLES选项可使三角形充满颜色。 最佳答案 使用glPolygonMode(face, model)设置填充模式: glPolygonMode(G
我想用一个包含 yuv 数据的采样器在 opengl es 着色器中将 yuv 转换为 rgb。我的代码如下: 1)我将 yuv 数据发送到纹理: GLES20.glTexImage2D(GLES20
我正在使用这样的域: http://www.domain.com/es/blabla.html 我想更改 .es 的/es 部分并将 URLS 转换为类似以下内容: http://www.domain
有谁知道OpenGL ES是否支持GL_TEXTURE_RECTANGLE?我计划将它用于 2D 图形以支持非二次幂图像。我当前的实现使用 alpha=0 填充的 POT 纹理,对于拉伸(stretc
我需要在具有 PowerVR SGX 硬件的 ARM 设备上实现离屏纹理渲染。 一切都完成了(使用了像素缓冲区和 OpenGL ES 2.0 API)。唯一 Unresolved 问题是速度很慢glR
这是一个奇怪的事情。我有一个片段着色器,据我所知只能返回黑色或红色,但它将像素渲染为白色。如果我删除一根特定的线,它会返回我期望的颜色。它适用于 WebGL,但不适用于 Raspberry Pi 上的
我正在考虑将一些 OpenGL 代码移植到 OpenGL ES 并且想知道这段代码到底做了什么: glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT) 因为 g
我正在考虑将一些 OpenGL 代码移植到 OpenGL ES 并且想知道这段代码到底做了什么: glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT) 因为 g
GLSL ES最多可以编译多少个程序?所以假设我创建了 100 个片段着色器,每个都有不同的效果。所以在运行时我编译所有这些并动态地我用 glUseProgram 交换它们。我假设每次我编译一个新的
我正在尝试使用顶点缓冲区对象来绘制圆,并在 iPhone 上的 OpenGL ES 2.0 中启用 GL_POINT_SMOOTH 来绘制点。 我使用以下 ES 1.0 渲染代码在 iPhone 4
为什么在 OpenGL ES 1.x 中缩放(均匀)对象会导致对象变轻? 更有意义的是它会更暗,因为法线被缩小是否也会使对象更暗?但由于某种原因,物体变轻了。当我放大时,对象变得更暗。在我看来,这应该
我正在尝试通过移植 some code 在 iOS 上的 OpenGL ES 2.0 中获得一些阴影效果。来自标准 GL。部分示例涉及将深度缓冲区复制到纹理: glBindTexture(GL_TEX
所以我正在使用 2D 骨骼动画系统。 有 X 个骨骼,每个骨骼至少有 1 个部分(一个四边形,两个三角形)。平均而言,我可能有 20 块骨头和 30 个部分。大多数骨骼都依赖于父骨骼,骨骼会每帧移动。
我在使用 ES 着色器时遇到了一些晦涩难懂的问题,而且我现在几乎没有想法了。 这是一些代码: .. precision mediump float; .. #define STEP (1f/6f) 5
我是一名优秀的程序员,十分优秀!