Note that there are some explanatory texts on larger screens.

plurals
  1. POmaking an iphone cube class
    primarykey
    data
    text
    <p>I followed <a href="http://www.raywenderlich.com/3664/opengl-es-2-0-for-iphone-tutorial" rel="nofollow">this tutorial</a> and I'm currently trying to create a class to draw cubes. The class populates the buffers in a function called setup and draws them in a function called draw.</p> <p>There are no errors however nothing is displayed on the screen.</p> <p>My question is basicly how do I go about making a class from which I can render cubes.</p> <p>Using Xcode 4.2, Opengl and Objective-C.</p> <p>[edit]</p> <pre><code>-(void)SetShader:(GLuint)InShader { glUseProgram(InShader); _positionSlot = glGetAttribLocation(InShader, "Position"); _colorSlot = glGetAttribLocation(InShader, "SourceColor"); glEnableVertexAttribArray(_positionSlot); glEnableVertexAttribArray(_colorSlot); _projectionUniform = glGetUniformLocation(InShader, "Projection"); _modelViewUniform = glGetUniformLocation(InShader, "Modelview"); _texCoordSlot = glGetAttribLocation(InShader, "TexCoordIn"); glEnableVertexAttribArray(_texCoordSlot); _textureUniform = glGetUniformLocation(InShader, "Texture"); } -(void)SetupVBO { GLuint vertexBuffer; glGenBuffers(1, &amp;vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(CubeVertices), CubeVertices, GL_STATIC_DRAW); GLuint indexBuffer; glGenBuffers(1, &amp;indexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(CubeIndices), CubeIndices, GL_STATIC_DRAW); } -(void)draw { glVertexAttribPointer(_positionSlot, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); glVertexAttribPointer(_colorSlot, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*) (sizeof(float) * 3)); glVertexAttribPointer(_texCoordSlot, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*) (sizeof(float) * 7)); glDrawElements(GL_TRIANGLES, sizeof(CubeIndices)/sizeof(CubeIndices[0]), GL_UNSIGNED_BYTE, 0); } -(void)render:(CADisplayLink*)displayLink { glClearColor(0, 0, 0.2, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); CC3GLMatrix *projection = [CC3GLMatrix matrix]; float h = 4.0f * self.frame.size.height / self.frame.size.width; [projection populateFromFrustumLeft:-2 andRight:2 andBottom:-h/2 andTop:h/2 andNear:4 andFar:10]; glUniformMatrix4fv(_projectionUniform, 1, 0, projection.glMatrix); CC3GLMatrix *modelView = [CC3GLMatrix matrix]; [modelView populateFromTranslation:CC3VectorMake(0, 0, -7)]; [modelView translateBy:CC3VectorMake(0,5,0)]; glUniformMatrix4fv(_modelViewUniform, 1, 0, modelView.glMatrix); glViewport(0, 0, self.frame.size.width, self.frame.size.height); [m_cube draw]; [_context presentRenderbuffer:GL_RENDERBUFFER]; } </code></pre>
    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.
    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