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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:43:51+00:00 2026-05-27T23:43:51+00:00

I am creating 2D game with OpenGL. Everytime I move my object, I have

  • 0

I am creating 2D game with OpenGL. Everytime I move my object, I have to call glLoadIdentity, because otherwise all objects will be moved, but glLoadIdentity also resets glOrtho call, so basically I ending with something like this:

#include <GL/glfw.h>

int main()
{
glfwInit();

glfwOpenWindowHint( GLFW_WINDOW_NO_RESIZE, GL_TRUE );
glfwOpenWindowHint( GLFW_FSAA_SAMPLES, 8 );
glfwOpenWindow( 800, 600, 0, 0, 255, 0, 32, 0, GLFW_WINDOW );

glfwSetWindowTitle( "title" );

glfwSwapInterval( 1 ); // also known as 'vsync'

glfwEnable( GLFW_KEY_REPEAT );
//glfwDisable( GLFW_MOUSE_CURSOR );

glOrtho(0.0, 1024, 768, 0, -1.0, 1.0); 
glMatrixMode( GL_MODELVIEW );

while( !glfwGetKey( GLFW_KEY_ESC ) )
{
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT);

    glLoadIdentity();
    glOrtho(0.0, 1024, 768, 0, -1.0, 1.0); 

    glTranslatef( 100, 0, 0 );

    glColor3f(0.5f,0.5f,1.0f);
    glBegin(GL_POLYGON);
      glVertex2f(100, 100);
      glVertex2f(100, 250);
      glVertex2f(250, 250);
      glVertex2f(250, 100);
    glEnd();

    glLoadIdentity();
    glOrtho(0.0, 1024, 768, 0, -1.0, 1.0); 

    glRotatef( 25,0,0,1);

    glBegin(GL_POLYGON);
      glVertex2f(300, 300);
      glVertex2f(300, 450);
      glVertex2f(450, 450);
      glVertex2f(450, 300);
    glEnd();

    glFlush();

    glfwSwapBuffers();
}

glfwTerminate();
}

How should it be done properly, to display, move and rotate objects with glOrtho enabled?

  • 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-27T23:43:51+00:00Added an answer on May 27, 2026 at 11:43 pm

    You need glPushMatrix() and glPopMatrix(). Checkout this tutorial:

    http://www.swiftless.com/tutorials/opengl/pop_and_push_matrices.html

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

Sidebar

Related Questions

Let's say I'm creating an OpenGL game in C++ that will have many objects
I'm creating a game in c++ and OpenGL and want an enemy to move
I'm creating an openGL game and so far I have been using .pngs in
I'm creating a game with points for doing little things, so I have a
I have started creating a game, and I added a second project, it's the
I'm in the process of creating a 2D game in OpenGL ES for the
I have an opengl game for iPhone/iPad (universal). I added the ability to send
I'm creating a game engine using wxWidgets and OpenGL. I'm trying to set up
I'm creating a game in which I have a somewhat complex method for creating
I'm creating c++ game server. The server creates many objects monster , and every

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.