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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:48:35+00:00 2026-06-07T07:48:35+00:00

I’m working on a game for iOS and I’m having some trouble with a

  • 0

I’m working on a game for iOS and I’m having some trouble with a texture using glDrawArrays (using cocos2D v1.0.1, with OpenGL ES 1.1). I first create an array of CGPoints that define the top and bottom of a hill, along with an array for the texture coordinates:

hillVertices[nHillVertices] = CGPointMake((topLeftVertexX)*CC_CONTENT_SCALE_FACTOR(), topLeftVertexY*CC_CONTENT_SCALE_FACTOR());
hillTexCoords[nHillVertices] = CGPointMake((topLeftVertexX)/textureSize.width, 0.0);
nHillVerticies++;
hillVertices[nHillVertices] = CGPointMake((bottomLeftVertexX)*CC_CONTENT_SCALE_FACTOR(), bottomLeftVertexY*CC_CONTENT_SCALE_FACTOR());
hillTexCoords[nHillVertices] = CGPointMake(topLeftVertexX)/textureSize.width, 1.0);
nHillVerticies++;

and then draw using…

glBindTexture(GL_TEXTURE_2D, groundSprite.texture.name);
glVertexPointer(2, GL_FLOAT, 0, hillVertices);
glTexCoordPointer(2, GL_FLOAT, 0, hillTexCoords);
glDrawArrays(GL_TRIANGLE_STRIP, 0, (nHillVertices-1));

In the beginning of the game (when the “topLeftVertexX” value is small), the hills look good…
Hills with a small x offset

But as the game continues, the x offset value (topLeftVertexX) increases, and things start to get worse…
middle x offset

And near the end, it gets bad…
x offset large

I think the problem is that in the beginning of the game, the “topLeftVertexX” value is small, so the result of

(topLeftVertexX)/textureSize.width

in

hillTexCoords[nHillVertices] = CGPointMake((topLeftVertexX)/textureSize.width, 0.0);

is small. However, as the game continues and the x values increase, I think the value is getting large enough to cause some sort of corruption. The textureSize is 512×512, and the “topLeftVertexX” begins at 0 at the beginning of the game, and goes up to about 200,000.

I have tried increasing the number of triangles (including adding additional strips), but that doesn’t help. I also tried using @jpsarda’s CCSpriteBiCurve class, and got the same result. I also tried using the glHints (such as GL_LINE_SMOOTH_HINT with GL_NICEST), but I haven’t found anything that helps.

Any ideas how I might fix this?

  • 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-07T07:48:37+00:00Added an answer on June 7, 2026 at 7:48 am

    It’s not getting corrupted, you’re just losing floating point precision as the magnitude of your number increases.

    As your number gets larger and larger, the delta between each successive point gets larger as well.

    In IEEE754, the difference between 1.f and the next larger number is 0.0000001

    At 200,000, the next larger number is 200,000.02. (courtesy of IEEE754 converter). I’m not even 100% positive what kind of FP precision GLSL uses (the quick ref card indicates it might be 14-bit mantissa in the fragment shader?). So in reality it could be even worse.

    If you’re just looking at a small window of a large number, then the error will continue to grow. I suspect that as the precision goes down, your texture starts to look more and more ‘blocky’.

    The only thing I can think of to do is to design your code such that the number does not have to grow unbounded forever. Is there a smarter way you could wrap the number over so that it doesn’t have to get so large?

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm making a simple page using Google Maps API 3. My first. One marker
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
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the

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.