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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:56:41+00:00 2026-05-20T22:56:41+00:00

I am trying to get my game to scroll as a player along the

  • 0

I am trying to get my game to scroll as a player along the y axis and the x axis.

Currently the coordinate systems of the window is out. 🙁

I am using the following line in openGl to scroll:

float tempX=px1;
float tempY=py1;
double left = tempX-screenWidth/2;
double right = screenWidth/2+tempX;
double bottom = tempY - screenWidth/2 + 300;
double top = screenHeight/2+tempY+ 300;
//gluOrtho2D(0,screenWidth,0,screenHeight);   (before scroll screen)
gluOrtho2D( left,  right, bottom ,  top);

px1 and py1 relate to my player and are updated as the player moves.
Currently if you get the window and resize it while the game is running you can see the images resize and my code is wrong as a square is displayed as a rectangle.

  • 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-20T22:56:42+00:00Added an answer on May 20, 2026 at 10:56 pm

    Something like this?

    #include <GL/glut.h>
    
    #include <map>
    using namespace std;
    
    size_t win_w = 0;
    size_t win_h = 0;
    
    void Box( int xoff, int yoff, int size = 10 )
    {
        glBegin(GL_QUADS);
            glVertex2f( xoff + -1*size, yoff + -1*size);
            glVertex2f( xoff +  1*size, yoff + -1*size);
            glVertex2f( xoff +  1*size, yoff +  1*size);
            glVertex2f( xoff + -1*size, yoff +  1*size);
        glEnd();    
    }
    
    map< int, bool > key_map;
    
    void keyboard( int key, int x, int y )
    {
        key_map[key] = true;
    }
    
    void keyboard_up( int key, int x, int y )
    {
        key_map[key] = false;
    }
    
    
    void display(void)
    {
        glEnable(GL_DEPTH_TEST);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
        static int center_x = 0;
        static int center_y = 0;
        if( key_map[GLUT_KEY_LEFT]  ) center_x--;
        if( key_map[GLUT_KEY_RIGHT] ) center_x++;
        if( key_map[GLUT_KEY_DOWN]  ) center_y--;
        if( key_map[GLUT_KEY_UP]    ) center_y++;
    
        double left   = center_x - win_w/2.0;
        double right  = center_x + win_w/2.0;
        double bottom = center_y - win_h/2.0;
        double top    = center_y + win_h/2.0;
    
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(left, right, bottom, top, -10, 10);
    
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    
        glColor3ub(255,0,0);
        Box( 10, 10 );
    
        glColor3ub(0,255,0);
        Box( 100, 100 );
    
        glutSwapBuffers();
    }
    
    void reshape(int w, int h)
    {
        win_w = w;
        win_h = h;
        glViewport(0, 0, w, h);
    }
    
    void idle()
    {
        glutPostRedisplay();
    }
    
    
    int main(int argc, char **argv)
    {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
    
        glutInitWindowSize(200,200);
        glutCreateWindow("Scroll");
    
        glutDisplayFunc(display);
        glutReshapeFunc(reshape);
        glutSpecialFunc( keyboard );
        glutSpecialUpFunc( keyboard_up );
    
        glutIdleFunc(idle);
        glutMainLoop();
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Creating a simple RPG game, first time using XNA. Trying to get my character
I'm trying to get the following Mongoid relationships to work, but the game field
I'm using Python 2.7 libtcod to make a Roguelike, and currently trying to get
I'm currently trying to get an ANN to play a video game and and
I am trying to get my game running smoothly on android using PlayN, everything
I'm trying to get my cursor visible in an XNA game using isMouseVisible, but
I'm currently trying to get a small brick-breaker game I made to effectively use
I've been trying to get this Sudoku game working, and I am still failing
I'm trying to get background music going for my XNA game, but the options
I'm trying to get the MKStoreKit working with my Cocos2D game. It look pretty

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.