OpenGL collision detection problem

I am trying to implement basic collision between a moving square and some obstacles. For the objects to render I used glRectf. I have two structs to detect collisions. One placed around the car and other around the obstacles and I am sending the xmin, ymin, xmax, ymax coordinates of the obstacles into the constructor of the obstasclecollision struct and sending the xmin, ymin etc for the car to the carrcollision struct and pushing all these values to two separate vectors which store the x,y values of player and obstacles. However when checking through the vector, the xmin and ymin coordinates never change or update as the car moves. Not sure what is wrong there and how I can make it update the xmin etc in the vector.


Unless you’re using OpenGL shaders to do collision detection, questions about collision detection are off-topic here.

No, I am not. I am using legacy opengl. Any idea where I should post it?


Well, since it’s 2D, it’s doable. Just use the stencil buffer for this. Set it full to 0, increment it for the first object, increment it for the second. Read back the buffer, and if there are any value at 2, there is collision.

I also believe Occlusion queries can do it should you have access to the extension.