Sign in to follow this  

[.net] c# and opengl + glReadPixels, gluUnProject compile errors

This topic is 3569 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i'm trying to convert a function for getting 3d world coords in opengl from the mouse position using opengl and c#. the function below in c/c++ works fine (aside from the array variables at the top which i changed to c#. however the rest of the function, primarily glReadPixels and gluUnProject give compiler errors.
CVector mouse2dto3d()
{
    unsafe
    {
        int[] viewport = new int[4];
        double[] modelview = new double[16];
        double[] projection = new double[16];
        float  wz;
        double x;
        double y;
        double z;

        Gl.glGetIntegerv(Gl.GL_VIEWPORT, viewport);
        Gl.glGetDoublev(Gl.GL_MODELVIEW_MATRIX, modelview);
        Gl.glGetDoublev(Gl.GL_PROJECTION_MATRIX, projection);
        Gl.glReadPixels(mouse_x, viewport[3] - mouse_x, 1, 1, Gl.GL_DEPTH_COMPONENT, Gl.GL_FLOAT, &wz);
        Glu.gluUnProject((double)mouse_y, (double)viewport[3] - (double)mouse_y, (double)wz, modelview, projection, viewport, (double)x, (double)y, (double)z);

        CVector temp = new CVector((float)x, (float)y, (float)z);

        return temp;
    }
}
Errors: Error 1 The best overloaded method match for 'Tao.OpenGl.Gl.glReadPixels(int, int, int, int, int, int, object)' has some invalid arguments Error 2 Argument '7': cannot convert from 'float*' to 'object' Error 3 The best overloaded method match for 'Tao.OpenGl.Glu.gluUnProject(double, double, double, double[], double[], int[], out double, out double, out double)' has some invalid arguments Error 4 Argument '7' must be passed with the 'out' keyword Error 5 Argument '8' must be passed with the 'out' keyword Error 6 Argument '9' must be passed with the 'out' keyword Thanks! Scott

Share this post


Link to post
Share on other sites
for glReadPixels, I'd imagine you'd need to make wz a float array, even if it only has one element, since pointers can't be converted to objects.

For gluUnProject, the issue is just what it says, you need to pass the x,y,z parameters as out:

Glu.gluUnProject((double)mouse_y, (double)viewport[3] - (double)mouse_y, (double)wz, modelview, projection, viewport, out x, out y, out z);

Share this post


Link to post
Share on other sites
glReadPixels has two overloads: IntPtr and object. Try this:


Gl.glReadPixels(mouse_x, viewport[3] - mouse_x, 1, 1, Gl.GL_DEPTH_COMPONENT, Gl.GL_FLOAT, (IntPtr)&wz);



Share this post


Link to post
Share on other sites
I'm trying:


Gl.glReadPixels((double)last_mouseX, (double)viewport[3] - (double)last_mouseY, 1, 1, Gl.GL_DEPTH_COMPONENT, Gl.GL_FLOAT, (IntPtr)&wz);


but it results in the error:

Error 1 'System.IntPtr' is a 'type' but is used like a 'variable'

thanks for the reply,
Scott

Share this post


Link to post
Share on other sites

This topic is 3569 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this