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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:48:18+00:00 2026-05-20T17:48:18+00:00

I am developing an iPhone game using OpenGL ES. I want to move the

  • 0

I am developing an iPhone game using OpenGL ES. I want to move the player using touch coordinates using code like the following:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
   CGPoint point=[[touches anyObject]locationInView:self.view];
   [eaglView render:point.x];
}// end 

then rendering within my OpenGL ES view using the following code:

- (void) render:(float )delta
{

    if(initialized==0) {
        [self initOpenGL];
    }

    static const GLfloat squareVertices[] = {
        -0.5f, -0.33f,
        0.5f, -0.33f,
        -0.5f,  0.33f,
        0.5f,  0.33f,
    };

    static const GLubyte squareColors[] = {
        255, 255,   0, 255,
        0,   255, 255, 255,
        0,     0,   0,   0,
        255,   0, 255, 255,
    };

    float transY = delta;

    // This application only creates a single context which is already set current at this point.
    // This call is redundant, but needed if dealing with multiple contexts.
    [EAGLContext setCurrentContext:context];

    // This application only creates a single default framebuffer which is already bound at this point.
    // This call is redundant, but needed if dealing with multiple framebuffers.
    //glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
    glViewport(0, 0, backingWidth, backingHeight);

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

    // Use shader program
    //glUseProgram(program);

    // Update uniform value
    //glUniform1f(uniforms[UNIFORM_TRANSLATE], (GLfloat)transY);
    //transY += 0.075f; 

    glVertexPointer(2, GL_FLOAT, 0, squareVertices); 
    glEnableClientState(GL_VERTEX_ARRAY);
    glColorPointer(4, GL_UNSIGNED_BYTE, 0, squareColors);
    glTranslatef(0.0f, (GLfloat)(sinf(transY)/2.0f), 0.0f);
    //transY += 0.0001f;

    glEnableClientState(GL_COLOR_ARRAY);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
    // Update attribute values

    // Validate program before drawing. This is a good check, but only really necessary in a debug build.
    // DEBUG macro must be defined in your debug configurations if that's not already the case.
    // Draw

    // This application only creates a single color renderbuffer which is already bound at this point.
    // This call is redundant, but needed if dealing with multiple renderbuffers.
    // glBindRenderbuffer(GL_RENDERBUFFER, renderBuffer);
    glBindRenderbufferOES(GL_RENDERBUFFER_OES,renderBuffer);
    [context presentRenderbuffer:GL_RENDERBUFFER_OES];
}

I can’t translate the object using window coordinates, so I have to convert it into normalized device coordinates. How would I go about converting from window coordinates to ones that I could use for translating my OpenGL ES model?

  • 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-20T17:48:19+00:00Added an answer on May 20, 2026 at 5:48 pm

    To convert from window to openGL coordinates you just need to flip the y axis (could be x depending on your orientation). If your device is in portrait mode you use the following code:

    CGPoint touch_point = [[touches anyObject] locationInView:self.view];
    touch_point = CGPointMake(touch_point.x, 480-touch_point.y); //Or you can put touch_point.y = 480-touch_point.y
    [eaglview renderTouchAtPoint:touch_point];
    

    Now if your device is in landscape you do the same except for the x axis:

    CGPoint touch_point = [[touches anyObject] locationInView:self.view];
    touch_point = CGPointMake(480-touch_point.x, touch_point.y);
    [eaglview renderTouchAtPoint:touch_point];
    

    This has worked for me, hope it works for you.

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

Sidebar

Related Questions

I'm developing a 2D game for the iPhone using OpenGL ES and I'd like
I'm currently developing an OpenGL ES game for the iPhone and iPod touch. I
I am developing several iPhone applications using UIKit. I want to learn and develop
this is my question. I'm developing a game on iPhone with OpenGL ES. I
I'm developing a simple 2D-game in OpenGL ES for the iPhone. My problem is
I am developing an iphone game using cocos2d and have it set to to
I am developing iPhone 2d game by using cocos2d. I need a Picker. Is
I am developing a 2D iPhone game by using cocos2d. I need a countdown
I am developing iphone game using coregraphics. but the speed is very slow. I
I am developing iPhone game application using one UIView and GraphicsContext. The belows are

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.