I got strange hit value by glRenderMode(GL_RENDER); on OpenGL

We found failed result when used selection Buffer.
When We try to pick same position line, we will always get an incorrect value.

#include "stdafx.h"
#define LFW_INCLUDE_NONE
#include <Windows.h> 
#include <gl\GL.h>
#include <gl\GLU.h>
#include "glfw\include\GLFW\glfw3.h"
#include "glfw\glut.h"
 
#include <stdlib.h>
#include <stdio.h>
 
bool g_bad_value = true;
void MouseButtonCallback(GLFWwindow* window, int button, int action, int mods) {
 
float current_aspect = 0;           
GLuint selectBuf[1024];             
GLuint hits;                        
GLint viewport[4];                  
 
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.7, 0.7, 0.7, 1.0);
glGetIntegerv(GL_VIEWPORT, viewport);
glSelectBuffer(1024, selectBuf);     
(void)glRenderMode(GL_SELECT);       
glInitNames();                       
glPushName(0);
glMatrixMode(GL_PROJECTION);         
glLoadIdentity();
gluPickMatrix(240, 240, 1.0, 1.0, viewport);
glMatrixMode(GL_MODELVIEW);     
glLoadIdentity();
for (int i = 0; i < 10; i++)
{
glLoadName(i);
glBegin(GL_LINES);
 
// if pick point is (0,0) so, the result needed 0 "hits" value.
// but, I got 10 hit value.
if(g_bad_value) 
{
glVertex3d(-0.8, -0.8, 0);
glVertex3d(-0.8, -0.8, 0);
}
else
{
// this is good 0 "hits" value.
glVertex3d(-0.7, -0.7, 0);
glVertex3d(-0.8, -0.8, 0);
}
 
glEnd();
 
}
hits = glRenderMode(GL_RENDER);
printf("%d\n", hits);
}
int main(void)
{
GLFWwindow* window;
 
if (!glfwInit())
exit(EXIT_FAILURE);
 
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
 
window = glfwCreateWindow(480, 480, "Simple example", NULL, NULL);
if (!window)
{
glfwTerminate();
exit(EXIT_FAILURE);
}
 
glfwSetMouseButtonCallback(window, MouseButtonCallback);
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
 
while (!glfwWindowShouldClose(window))
{
 
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.7, 0.7, 0.7, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW_MATRIX);
glLoadIdentity();
glColor3d(1, 0, 0);
glBegin(GL_LINES);
if (g_bad_value)
{
glVertex3d(-0.8, -0.8, 0);
glVertex3d(-0.8, -0.8, 0);
}
else
{
glVertex3d(-0.7, -0.7, 0);
glVertex3d(-0.8, -0.8, 0);
}
 
glEnd();
glfwSwapBuffers(window);
glfwPollEvents();
}
 
glfwDestroyWindow(window);
 glfwTerminate();
exit(EXIT_SUCCESS);
}

The problem occurs depending on the GPU.

Not Bug Result GPU:
Intel Iris Xe Graphics G7 96EU(31.0.101.4091)

Bug Result GPU
Intel Iris Xe Graphics G7 96EU(Version:31.0.101.4672)
Intel Iris Xe Graphics G7 96EU(Version:31.0.101.4826)
Intel UHD Graphics 770 Alder Lake (Version:31.0.101.4672)

Is there any way to solve it?

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.