More problems with gluunproject

BlitzMax Forums/OpenGL Module/More problems with gluunproject

-wyvern(Posted 2006) [#1]
As per your advice I downloaded and have tried to implement the NeHe article on gluunproject, but it doesn't work out quite as I had planned:

I still can't convert the mouses X and Y co-ordinates into 3D opengl co-ordinates that my program can use. I don't know if this is a maths problem or due to my lack of experience with blitz. Basically, my program involves drawing a grid along the X and Y 3D axes. I want to be able to find out which square of the grid my mouse pointer is over, given that the Z co-ordinate will always be zero:

Function get3dposition:tvector3(x,y)
'Converts 2d co-ordinates into 3d co-ordinates.
Local viewport[4],projection:Double[16],modelview:Double[16]
Local winx#,winy#,winz#
Local posx:Double,posy:Double,posz:Double
glgetdoublev(GL_MODELVIEW_MATRIX,modelview)
glgetdoublev(GL_PROJECTION_MATRIX,projection)
glgetintegerv(GL_VIEWPORT,viewport)

winx=x
winy=viewport[3]-y
glreadpixels(winx, winy, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, Varptr winz)

font.draw2d (100,100,"Win X"+winx+" Win Y"+winy+" Win Z"+winz) 'debugging

gluUnProject( winx, winy, winz, modelview, projection, viewport, Varptr posx, Varptr posy, Varptr posz)

Return tvector3.create(posx, posy, posz)
End Function

Whatever I do, winz is always 1.00000 and posx, posy and posz are nonsensical, unusable values. I have googled for information about the mechanics of the commands gluunproject and glreadpixels and I can't see how I could be using them incorrectly; perhaps I am interpreting the returned values wrong. Please help me, this is a very frustrating problem.


ozak(Posted 2006) [#2]
Be carefull where you call this. Check your return as as among others: "GL_INVALID_OPERATION is generated if glReadPixels is called between a call to glBegin and the corresponding call to glEnd."