Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7092023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:15:40+00:00 2026-05-28T08:15:40+00:00

I am new to OpenGL ES programming. I found a good tutorial to start

  • 0

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:

[model update];
[model load];

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.

-(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;
}  

And here is the loading method:

- (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:&error];
if (info == nil) {
    NSLog(@"Error loading file: %@", [error localizedDescription]);
}
self.effect.texture2d0.name = info.name;
self.effect.texture2d0.enabled = true;

glGenVertexArraysOES(1, &vertexArray);
glBindVertexArrayOES(vertexArray);

glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);

glGenBuffers(1, &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);
}

And here is the rendering method:

- (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);
}

Any help would be appreciated. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:15:40+00:00Added an answer on May 28, 2026 at 8:15 am

    There’s not really an ‘error’ here. The problem is that you’re not really setting up the projection and modelview matrices so that it frames your model nicely. There’s no magic solution. You should consider the vertices in the model that you are drawing (do they go up to 100? 1000? Just 0.5?) and choose appropriate settings for GLKMatrix4MakePerspective that put them squarely in the screen.

    As a short cut, (since you said that without the translation and rotation it fills the whole screen), you can replace those transformations with a scale command to scale down the size of the object.

    Something like:

    GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.1f, 0.1f, 0.1f);   
    

    As general advice, try to consider the effect of each command individually. If you’re looking for an introduction to projection/transformation concepts, I found this link: http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Chapter-3:-3D-transformation-and-projection.html Skip down to the section called Projection and world space.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As I'm new to OpenGL programming, I have tried to test the sample code
I am new to OpenGL. Wondering if there is any good Scenegraph API/framework for
I am new to OpenGL programming.I have made a rotating cube with different images
I have just began opengl programming in android and i am fairly new to
I'm new to OpenGL and graphics programming in general, though I've always been interested
I am new to opengl programming, but I am doing something very basic, and
What are some good resources for learning OpenGL 4.1 aimed at someone relatively new
I am new to opengl I tried to make an isosurface by reading from
I have two years of experience on iPhone programming but totally new to OpenGL.
I was just starting a new opengl project in xcode. When I was going

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.