Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL ES no Longer Displaying Object
    primarykey
    data
    text
    <p>I am new to OpenGL ES programming. I found a good tutorial to start and the project displayed a square. I then tried to move the most OpenGL code out of the View Controller to a Model object which would store vertices, color, etc and then in the View Controller I would just call:</p> <pre><code>[model update]; [model load]; </code></pre> <p>This way it would be more practice if I had several models to display. And since I did this the cube no longer displays on screen. I think I pinpointed to error to the update method where all the model view matrix calculations occur, because when I comment out this method the cube displays but it just fills the screen.</p> <pre><code>-(void)update: (int)width And:(int)height{ float aspect = (width/height); GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective( GLKMathDegreesToRadians(65.0f), aspect, 4.0f, 10.0f); self.effect.transform.projectionMatrix = projectionMatrix; GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, 6.0f); rotation += 90; modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, GLKMathDegreesToRadians(rotation), 0, 0, 1); self.effect.transform.modelviewMatrix = modelViewMatrix; } </code></pre> <p>And here is the loading method:</p> <pre><code>- (void)load{ self.effect = [[GLKBaseEffect alloc] init]; NSDictionary * options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], GLKTextureLoaderOriginBottomLeft, nil]; NSError * error; NSString *path = [[NSBundle mainBundle] pathForResource:@"tile_floor" ofType:@"png"]; GLKTextureInfo * info = [GLKTextureLoader textureWithContentsOfFile:path options:options error:&amp;error]; if (info == nil) { NSLog(@"Error loading file: %@", [error localizedDescription]); } self.effect.texture2d0.name = info.name; self.effect.texture2d0.enabled = true; glGenVertexArraysOES(1, &amp;vertexArray); glBindVertexArrayOES(vertexArray); glGenBuffers(1, &amp;vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW); glGenBuffers(1, &amp;indexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices), Indices, GL_STATIC_DRAW); glEnableVertexAttribArray(GLKVertexAttribPosition); glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, Position)); glEnableVertexAttribArray(GLKVertexAttribColor); glVertexAttribPointer(GLKVertexAttribColor, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, Color)); glEnableVertexAttribArray(GLKVertexAttribTexCoord0); glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, TexCoord)); glBindVertexArrayOES(0); } </code></pre> <p>And here is the rendering method:</p> <pre><code>- (void)render{ [self.effect prepareToDraw]; glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); glBindVertexArrayOES(vertexArray); glDrawElements(GL_TRIANGLES, sizeof(Indices)/sizeof(Indices[0]), GL_UNSIGNED_BYTE, 0); } </code></pre> <p>Any help would be appreciated. Thanks. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload