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

  • Home
  • SEARCH
  • 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 7765039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:04:32+00:00 2026-06-01T15:04:32+00:00

I am picking up the opengl es 2.0 with GLKit. I can successfully draw

  • 0

I am picking up the opengl es 2.0 with GLKit. I can successfully draw shapes like squares, triangles, cube etc.

I have problem drawing points, here is my code which isn’t working on device (iPod 4), though I can see the Points/dots in retina simulator.

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect {

     //White background color
    glClearColor(1.0, 1.0, 1.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);

    [self.effect prepareToDraw];  

    //USING _program
    glUseProgram(_program);

    GLfloat vert[] = {0,0, 0.1,0.1, 0.2,0.2, 0.3,0.3, 0.4,0.4, 0.5,0.5};
    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
    glEnableVertexAttribArray(GLKVertexAttribPosition);
    glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, vert);
    glDrawArrays(GL_POINTS, 0, 5);
    glDisableVertexAttribArray(GLKVertexAttribPosition);
}

and here is my update method just for ref:

- (void)update {
    float aspect = fabsf(self.view.bounds.size.width / self.view.bounds.size.height);
    GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65.0f), aspect, 4.0f, 10.0f);    
    self.effect.transform.projectionMatrix = projectionMatrix;

    //Since visible range is 4 to 10 so have to mave back in z
    GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -6.0f);
    self.effect.transform.modelviewMatrix = modelViewMatrix;   
}

and following is how I am defining the effect:

self.effect = [[GLKBaseEffect alloc] init];
self.effect.useConstantColor = GL_TRUE;
self.effect.constantColor = GLKVector4Make(0.0, 0.0, 1.0, 1.0); //Blue color

So that the points are visible on white background.

Can someone point any flaw in this code? I am not sure why it isn’t showing on device since triangles, squares and cubes where all visible.
Any help is appreciated.

Edit:

I have not used shaders before so this is my first time. As Ben mentioned the example code. Here’s now what I am doing:

I have VertexShader.glsl and FragmentShader.glsl files:

VertexShader.glsl

void main()
{
    gl_PointSize = 10.0;
}

FragmentShader.glsl

void main()
{

}

I am setting up the shader just before I create the effect and just after I set EAGLContext:

// Setup shader
GLuint vertexShader = [self createShaderWithFile:@"VertexShader.glsl" type:GL_VERTEX_SHADER];
GLuint fragmentShader = [self createShaderWithFile:@"FragmentShader.glsl" type:GL_FRAGMENT_SHADER];
_program = glCreateProgram();

glAttachShader(_program, vertexShader);
glAttachShader(_program, fragmentShader);
glLinkProgram(_program);

GLint linked = 0;
glGetProgramiv(_program, GL_LINK_STATUS, &linked);
if (linked == 0) {
    glDeleteProgram(_program);
    return;
}

And here is the createShaderWithFile method:

- (GLuint)createShaderWithFile:(NSString *)filename type:(GLenum)type 
{
    GLuint shader = glCreateShader(type);

    if (shader == 0) {
        return 0;
    }

    NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:filename];
    NSString *shaderString = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
    const GLchar *shaderSource = [shaderString cStringUsingEncoding:NSUTF8StringEncoding];

    glShaderSource(shader, 1, &shaderSource, NULL);
    glCompileShader(shader);

    GLint success = 0;
    glGetShaderiv(shader, GL_COMPILE_STATUS, &success);

    if (success == 0) {
        char errorMsg[2048];
        glGetShaderInfoLog(shader, sizeof(errorMsg), NULL, errorMsg);
        NSString *errorString = [NSString stringWithCString:errorMsg encoding:NSUTF8StringEncoding];
        NSLog(@"Failed to compile %@: %@", filename, errorString);
        glDeleteShader(shader);
        return 0;
    }

    return shader;
}

I have also updated the drawRect method above.

Here is the link to this project: http://dl.dropbox.com/u/36638938/Template.zip

  • 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-06-01T15:04:32+00:00Added an answer on June 1, 2026 at 3:04 pm

    Try setting the gl_PointSize variable in the vertex shader to a larger value. Maybe you can’t see a single pixel on the device.

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

Sidebar

Related Questions

In order to do object picking in OpenGL, do I really have to render
I am using pixel colour picking to work out which OpenGL object I have
I have scons picking up a very odd dependency cycle. It goes something like
I have a little problem picking the right language to write my daemon, I
I have the following code to draw an openGL scene void QGLDiagramWidget::paintGL() { glClearColor(0.2f,
I am drawing a mesh of triangles using glDrawElements and would like to be
I have been picking my brain lately and can't seem to figure out how
I'm trying to implement picking using Pyglet's OpenGL wrapper, but I'm having trouble converting
I'm using opengl's selection buffer, but i'm experiencing a trouble, the picking works perfectly
Been slowly picking up the basics in IOS Programming, but seemed to have hit

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.