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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:36:32+00:00 2026-06-11T03:36:32+00:00

I am using this code from NEHE tutorial in my MFC based application on

  • 0

I am using this code from NEHE tutorial in my MFC based application on mouseclick

void CRightOGL::OnLButtonDown(UINT nFlags, CPoint point)

{
// TODO: Add your message handler code here and/or call default

GLint viewport[4];
GLdouble modelview[16]={0};
GLdouble projection[16];
GLfloat winX, winY, winZ;
GLdouble posX, posY, posZ;
GLfloat mv[16];

glGetFloatv( GL_MODELVIEW_MATRIX, mv );
glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
glGetDoublev( GL_PROJECTION_MATRIX, projection );
glGetIntegerv( GL_VIEWPORT, viewport );

winX = (float)point.x;
winY = (float)viewport[3] - (float)point.y;
glReadPixels(point.x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );

gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);


COpenGLControl::OnLButtonDown(nFlags, point);

    }

But the problem is that i am getting incorrect values every time posX, &posY, &posZ… and values always comes in -9.25555 , -9.255555 ,-9.255555. Not only this but also modelview matrix is returning same -9.555 value everytime.

If i initialize everything as 0 then posX,posY and PosZ returns me only 0 instead of correct coordinates. Mouse x and y values are perfectly fine so from mouse side there is no issue.

What i am doing wrong?

my opengl initialization code is as follow

void COpenGLControl::oglInitialize(void)
{
// Initial Setup:
//
static PIXELFORMATDESCRIPTOR pfd =
{
    sizeof(PIXELFORMATDESCRIPTOR),
    1,
    PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
    PFD_TYPE_RGBA,
    32, // bit depth
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    16, // z-buffer depth
    0, 0, 0, 0, 0, 0, 0,
};


// Get device context only once.
hdc = GetDC()->m_hDC;

// Pixel format.
m_nPixelFormat = ChoosePixelFormat(hdc, &pfd);
SetPixelFormat(hdc, m_nPixelFormat, &pfd);

// Create the OpenGL Rendering Context.
hrc = wglCreateContext(hdc);
wglMakeCurrent(hdc, hrc);

// Basic Setup:
//
// Set color to use when clearing the background.
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClearDepth(1.0f);

// Turn on backface culling
glFrontFace(GL_CCW);
glCullFace(GL_BACK);

// Turn on depth testing
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH);


//glEnable(GL_TEXTURE_2D);  // Enable 2D textures
// Send draw request

GLenum a = glGetError();

OnDraw(NULL);
}
  • 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-11T03:36:34+00:00Added an answer on June 11, 2026 at 3:36 am

    Okay i figured out the issue generating due to the below scenario

    i am using draw function between setting of two different hdc , because i have two different picture control window’s of mfc and both has different drawing. That is why inside the mouse down or mouse click event when i was using above gl code it always used to give me error 1282 by s = glGetError().

    So to make it work i just added the above code within the

    wglMakeCurrent(hdc, hrc);
    
    //my code
    
    wglMakeCurrent(NULL, NULL);
    

    and it worked and all the x y and z values are now on the screen

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

Sidebar

Related Questions

I'm using this code from Microsoft to play audio notifications for my application. It's
I'm launching Excel from code using this code : var excelApp = new MSExcel.Application
I am using this code from css tips and tricks to cover a background
I am using this code taken from here : import smtplib def prompt(prompt): return
I am using this code phone calling from iPhone its calling directly to particular
When using this code (simplified for asking): var rows1 = (from t1 in db.TABLE1
I'm using this code to extract text from the database and it works well
I am using this code to pull my string array from my values folder:
I'm using this code to render an image from view. Then i am saving
I am using this code to sum values from multiple radio buttons : $(document).ready(function(){

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.