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 920961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:48:03+00:00 2026-05-15T18:48:03+00:00

I’m developing an OpenGL-ES game of life program for the iPhone and I have

  • 0

I’m developing an OpenGL-ES game of life program for the iPhone and I have an array that contains the boolean values of the entire grid, what I did for the array of the grid was:

grid = (BOOL *)malloc(2*XSize*YSize*sizeof(BOOL));

and I want to know what would be a good way of plotting this linear array to the screen.

I’ve tried to create the Vertices array and then plot via glDrawArray but I can’t seem to get it right so I was wondering if anyone else could help me. This is the method I’m trying right now that when rendered creates artifacts for some reason:

- (void)GridToVertices {
    int current = 0;

    for(int y=-backingHeight/2;y<backingHeight/2;y++) {
        for(int x=-backingWidth/2;x<backingWidth/2;x++) {
            Vertices[current] = x;
            Vertices[current+1] = y;
            current+=2;
        }
    }
}

And then rendering it like so:

- (void)render {
    [self GridToVertices];
    [self GridToColors];

    [EAGLContext setCurrentContext:context];

    glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);
    glViewport(0, 0, backingWidth, backingHeight);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    float Left = -backingWidth/2;
    float Right = backingWidth/2;
    float Up = -backingHeight/2;
    float Down = backingHeight/2;
    glOrthof(Left, Right, Up, Down, -1.0f, 1.0f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    glVertexPointer(2, GL_FLOAT, 0, Vertices);
    glEnableClientState(GL_VERTEX_ARRAY);
    glColorPointer(4, GL_UNSIGNED_BYTE, 0, Colors);
    glEnableClientState(GL_COLOR_ARRAY);

    glDrawArrays(GL_POINTS, 0, [grid resolution]);

    glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
    [context presentRenderbuffer:GL_RENDERBUFFER_OES];
}
  • 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-15T18:48:03+00:00Added an answer on May 15, 2026 at 6:48 pm

    Actually, the correct fix in your case is either to change your call to glOrthof to:

    glOrthof(Left-0.5f, Right-0.5f, Up-0.5f, Down-0.5f, -1.0f, 1.0f);
    

    or leave your call to glOrthof in its original form and add a translation when you’re setting up your modelview matrix:

    glTranslatef(0.5f, 0.5f, 0.0f);
    

    The reason for this comes from the OpenGL ES rules for point rasterization, as described in section 3.3.1 of the specification, which states:

    In the default state, a point is rasterized by truncating its xw and yw coordinates (recall that the subscripts indicate that these are x and y window coordinates) to integers. This (x, y) address, along with data derived from the data associated with the vertex corresponding to the point, is sent as a single fragment to the per-fragment stage of the GL.

    The important thing to note is that the window coordinate of a point is the result of applying the modelview and projection matrices to the point’s position, then scaling by your viewport. In your case, this winds up multiplying your points’ x and y coordinates by the reciprocal of backingWidth and backingHeight, then by backingWidth and backingHeight again, which isn’t guaranteed to leave them exactly integral, because of floating-point rounding at various stages in the calculations.

    To minimize any occurrences of rounding/truncation putting your points where you don’t expect, you want your point’s final window coordinates to land right on the center of a pixel. Remember that the pixel (x, y) in the framebuffer actually corresponds to a rectangle spanning (x, y) to (x+1, y+1), so you want to shift them by 0.5 in both x and y. Both snippets I posted do that, but in different ways. (You need only do one of them.)

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.