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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:35:00+00:00 2026-05-21T14:35:00+00:00

I would like an explanation of why XCode’s OpenGl ES Sample works, please. It

  • 0

I would like an explanation of why XCode’s OpenGl ES Sample works, please. It does the following to start the drawFrame method (in the blablaViewController.m – name is dependent on the project’s name):

//sets up a CADisplayLink to do a regular (draw & update) call like this
CADisplayLink *aDisplayLink = [[UIScreen mainScreen] displayLinkWithTarget:self 
    selector:@selector(drawFrame)];
[aDisplayLink setFrameInterval:animationFrameInterval];
[aDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

and inside the drawFrame method it does the following:

//start of method
...
static float transY = 0.0f;
...
//Quite a lot of OpenGl code, I am showing only parts of the OpenGL ES1 version:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, (GLfloat)(sinf(transY)/2.0f), 0.0f);
transY += 0.075f;
...
//end of method

I don’t know a lot of Objective C yet, but the way this transY variable is reset, then incremented in the same method is very weird. Since the GL_MODELVIEW matrix is reset to identity before being shifted, I don’t think it could keep an accumulated value in opengl somewhere.

Is the static keyword the trick here? Does Objective C ignore all future variable declarations once something has been declared static once?

Thanks for the help!

  • 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-21T14:35:01+00:00Added an answer on May 21, 2026 at 2:35 pm

    Static variables get initializated at compile time in the binary, so only once, and for that reason you’re forbidden to assign dynamic values for their initialization. Here, the variable transY is not set to 0.0 at every method call, but just on startup. That’s why subsequent calls of the method can retrieve the old value.

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

Sidebar

Related Questions

I know what the following function does I would just like an explanation of
Would like to get step-by-step explanation of the following function in Haskell fibs =
Hi I would like to have an explanation regarding the following code. Here Sometimes
I would like to solve the following problem using constraints but i actually don't
I would like to start the Apache service on my Windows 7 with the
NL-Complexity appears to be related to NP-complexity, and i would like a non-mathematic explanation
I would like to write a fuzzy date method for calculating dates in Objective-C
I would like to have a detailed explanation. How would I use the Lua
I would like to throw exceptions with meaningful explanation (socket handle, process id, network
i would like to implement a quartz composition into my iOS app in xcode

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.