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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:41:22+00:00 2026-06-14T08:41:22+00:00

Using SCREEN_WIDTH = 1200, and SCREEN_HEIGHT = 800. First, I draw a box to

  • 0

Using SCREEN_WIDTH = 1200, and SCREEN_HEIGHT = 800.

First, I draw a box to the screen at (x = 0, y = 0, w = 40, h = 40);

Then I use the handleMouse Function to return the x and y coordinates of where the mouse is clicked.

The problem is, when the program starts in non-Maximized windowed mode, when I click on (What appears to be) the very bottom right corner of the box the coordinates returned are x = 40, y = 32. When I think it should be returning x = 40, y = 40.

I don’t know whether the problem is if its not being drawn right, or the functions is returning the wrong x/y.

I believe I understand how openGL rendering, transformation and glOrth work, but I could be completely wrong. I have seen a few suggestions online saying that the Windows Decor(Using windows 7) can cause this problem, but have done very little explaining and provided no solution.

This is my entire source code. I have stripped off everything from my game down to the basics, and the problem still persists 🙁 . I added two pictures so people could see my problem. In NON-MAXIMIZED WINDOW(the top picture), when clicking the bottom-right corner, the coordinates returned are 41,32; The y coordinate is smaller than it should be. And in the MAXIMIZED WINDOW(the bottom picture), when clicking the same corner, It returns the correct coordinates 40, 40. These results occur for both my original source code and genpfault’s suggested code.

//Turns out I can’t post Pictures :(, links instead.

non-Maximized Windowed!

Maximized Windowed!

main.cpp
int main( int argc, char* args[] )
{
    //Initialize FreeGLUT
    glutInit( &argc, args );

    //Create OpenGL 2.1 context
    glutInitContextVersion( 2, 1 );

    //Create Double Buffered Window
    glutInitDisplayMode( GLUT_DOUBLE );
    glutInitWindowSize( SCREEN_WIDTH, SCREEN_HEIGHT );
    glutCreateWindow( "OpenGL" );

    //Do post window/context creation initialization
    if( !initGL() )
    {
        printf( "Unable to initialize graphics library!\n" );
        return 1;
    }
    //initGame();


    glutMouseFunc(handleMouse);


    glutDisplayFunc( render );


    glutMainLoop();

    return 0;
}

Functions.h

#ifndef FUNCTIONS_H
#define FUNCTIONS_H

bool initGL();

void render();

void handleMouse(int button, int state, int x, int y);

#endif

Functions.cpp

bool initGL()
{

    //Initialize clear color
    glClearColor( 0.f, 0.f, 0.f, 1.f );

    //Check for error
    GLenum error = glGetError();
    if( error != GL_NO_ERROR )
    {
        //cout <<"Error initializing OpenGL! " << gluErrorString( error ) << endl;
        return false;
    }

    return true;
}

void render()
{

    //Clear color buffer
    glClear( GL_COLOR_BUFFER_BIT );
    glColor3f(1.f,1.f,1.f);

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluOrtho2D(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glBegin(GL_QUADS);
        glVertex2f(0,0);
        glVertex2f(0, 41);
        glVertex2f(41, 41);
        glVertex2f(41, 0);
    glEnd();

    glutSwapBuffers();
}

void handleMouse(int button, int state, int x, int y)
{

    std::cout << x << '\t' << y << std::endl;

}

constants.h

const int SCREEN_WIDTH = 1200;
const int SCREEN_HEIGHT = 800;
  • 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-14T08:41:23+00:00Added an answer on June 14, 2026 at 8:41 am

    This works fine for me on Windows 7 on Aero and Classic:

    #include <GL/glut.h>
    #include <iostream>
    
    void render()
    {
        glClearColor( 0, 0, 0, 1 );
        glClear( GL_COLOR_BUFFER_BIT );
    
        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
        double w = glutGet( GLUT_WINDOW_WIDTH );
        double h = glutGet( GLUT_WINDOW_HEIGHT );
        glOrtho(0, w, h, 0, -1, 1);
    
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    
        glColor3ub( 255, 255, 255 );
        glBegin(GL_QUADS);
            glVertex2f(0,0);
            glVertex2f(41, 0);
            glVertex2f(41, 41);
            glVertex2f(0, 41);
        glEnd();
    
        glutSwapBuffers();
    }
    
    void handleMouse(int button, int state, int x, int y)
    {
        std::cout << x << '\t' << y << std::endl;
    }
    
    int main( int argc, char* args[] )
    {
        glutInit( &argc, args );
    
        glutInitDisplayMode( GLUT_DOUBLE );
        glutInitWindowSize( 640, 480 );
        glutCreateWindow( "OpenGL" );
    
        glutMouseFunc(handleMouse);
        glutDisplayFunc( render );
        glutMainLoop();
        return 0;
    }
    

    Most notably I added the runtime glutGet() window size queries to render().

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

Sidebar

Related Questions

I have objects placed on the screen using x/y coordinates. I want a way
I'm trying to draw a rectangle on my screen using the win32 python libs.
I'm displaying pop up window using the below code: var left = (screen.width/2)-(400/2); var
I'm using VS2008 and I created an app with a login screen. That screen
The post summarizes problems in using Screen in Mac's terminal when you have the
I've recently started using GNU Screen but have run into a very annoying problem.
I have designed the screen using this relative layout. <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android
Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
How can I display a splash screen using C or C++ in Windows? What
I'm drawing directly to the screen using BitBlt and GetDC(IntPtr.Zero) . Is there some

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.