I am fairly new to IOS, however, I am trying to port a native OpenGL ES triangle example I did on Android. Info on the details of my problem can be found here (Well it won’t let me add a url so I will copy my post).
It only let me post a “little” of the code so here are the main parts in question, I am pretty sure the shader compiles.
viewController.m
#import "game-gl.h"
....
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
renderFrameLine();
}
game-gl.c
GLbyte vShaderStr[] =
"attribute vec4 vPosition;
"
"void main()
"
"{
"
" gl_Position = vPosition;
"
"}
";
GLbyte fShaderStr[] = "precision mediump float;"
"void main()
"
"{
"
" gl_FragColor = vec4 (0.0, 1.0, 0.0, 1.0);
"
"}
";
GLuint LoadShader(GLenum type, const char *shaderSrc) {
#ifdef __APPLE__
printf("Compiling Shader
");
#endif
GLuint shader;
GLint compiled;
// Create the shader object
shader = glCreateShader(type);
// if (shader == 0){
//#ifdef __APPLE__
// printf("Shader Failed %d
", type);
//#endif
// return 0;
// }
// Load the shader source
glShaderSource(shader, 1, &shaderSrc, NULL);
// Compile the shader
glCompileShader(shader);
// Check the compile status
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
if (!compiled) {
#ifdef __APPLE__
printf("Shader Failed
");
#endif
GLint infoLen = 0;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
glDeleteShader(shader);
return 0;
}
else{
#ifdef __APPLE__
printf("Shader Created
");
#endif
}
return shader;
}
....
vertexShader = LoadShader(GL_VERTEX_SHADER, vShaderStr);
fragmentShader = LoadShader(GL_FRAGMENT_SHADER, fShaderStr);
....
float s = 0.5F;
void renderFrameLine() {
#ifdef __APPLE__
//printf("Inside Render Line
");
if(f>1.0f){
f = 0.0f;
}
else{
f = f+.01;
}
glClearColor(0.25f, 0.8f, f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
#else
glClear(GL_COLOR_BUFFER_BIT);
#endif
GLfloat vVertices[] = { s, s, 0.0f, s, -s, 0.0f, -s, s,
0.0f};
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 3);
}
I am beating my head against the wall here, the code works fine on Android, but on ios I see the background changing but not the triangle. Any ideas?