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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:36:27+00:00 2026-05-11T09:36:27+00:00

I am creating a simple 2D OpenGL application but I seem to be experiencing

  • 0

I am creating a simple 2D OpenGL application but I seem to be experiencing some camera issues. When I draw a rectangle at (20,20) it is drawn at (25,20) or so. When I draw it at (100, 20) it is drawn at 125 or so. For some reasons everything is being shifted to the right by a few %.

I have pasted a trimmed down version here http://pastebin.com/m56491c4c

Is there something wrong with the way I am setting up GLUT? I know it’s not my objects doing anything weird since the same thing happens when I disable them.

Thanks in advance.

  • 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. 2026-05-11T09:36:28+00:00Added an answer on May 11, 2026 at 9:36 am

    You need to set the projection matrix inside the reshape function (resize()), which also automatically solves the problem of the user resizing the window:

    void resize(int w, int h) {   glMatrixMode(GL_PROJECTION);   glLoadIdentity();   gluOrtho2D(0, w, h, 0); } 

    And then in your draw function, make sure that the matrix mode is model-view:

    void draw() {   glMatrixMode(GL_MODELVIEW);   glLoadIdentity();   ... } 

    Other problems with your code:

    • You probably shouldn’t be calling glutPostRedisplay() at the end of draw(). This is going to make your CPU run at 100%. You can instead use glutTimerFunc() to still have updates every some number of milliseconds.
    • In processMouse(), you’re using wsprintf() on an array of chars: wsprintf() takes an array of wide characters (wchar_t), so you should make the local variable s of type wchar_t[], or use sprintf() and MessageBoxA() instead of wsprintf() and MessageBoxW() (to which MessageBox() expands as a macro when compiling a Unicode application, which I’m assuming you’re doing). You’re also vulnerable to a buffer overflow — you should use a buffer of at least 12 characters, even though realistically you’ll never be passed a very large x value. Finally, you should also use snprintf()/wsnprintf() instead of sprintf()/wsprintf() to protect against the buffer overflow.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a simple opengl application which obviously includes some 3d-objects and textures.
I'm trying to figure out a simple to draw some text in OpenGL. My
I'm creating an Android app utilising OpenGL ES, and need some help with the
I'm creating a simple API that creates typed classes based on JSON data that
I'm creating a simple tag system that allows me to link a tag to
I am using Visual Studio 2008 Express and I tried creating a simple console
One simple method I've used in the past is basically just creating a second
The issue is simple really. Instead of creating folders in Visual Studio, I create
I'm creating a threaded message board and I'm trying to keep it simple. There's
I'm working on an application that needs to quickly render simple 3D scenes on

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.