Sign in to follow this  
ih8lag

gluproject

Recommended Posts

I am experimenting with portal rendering and am using screen co-ordinates to determine visibility.

I have setup a test app and have drawn a rectangular quad to the screen to simulate my portal as a LINE_LOOP everything looks fine. When I take the same 4 points and gluproject them to obtain the screen coordinates and then draw them orthographically to the screen they should overlay right on top of the each other but they dont.


glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW_MATRIX);
glLoadIdentity();
glMatrixMode(GL_PROJECTION_MATRIX);
glLoadIdentity();

gluLookAt(0, 0, -1, 0, 0, 0, 0, 1, 0);

double modl[16], proj[16], x, y, z;
int view[4];

glGetDoublev(GL_PROJECTION_MATRIX, &proj[0]);
glGetDoublev(GL_MODELVIEW_MATRIX, &modl[0]);
glGetIntegerv(GL_VIEWPORT, &view[0]);

// project the portal points to the screen
for(int j = 0; j < 2; j++)
for(int i = 0; i < 4; i++)
{
gluProject(portals[j].points[i].x, portals[j].points[i].y, portals[j].points[i].z,
modl, proj, view, &x, &y, &z);
portals[j].ppoints[i].x = x;
portals[j].ppoints[i].y = y;
}

// draw simulated portal to screen
glColor3f(0, 1, 0);
glBegin(GL_LINE_LOOP);
glVertex3fv(&portals[0].ppoints[0].x);
glVertex3fv(&portals[0].ppoints[1].x);
glVertex3fv(&portals[0].ppoints[2].x);
glVertex3fv(&portals[0].ppoints[3].x);
glEnd();

// draw projected coordinates
gluOrtho2D ( 0, 1024, 0, 768 );
glColor3f(1, 0, 0);
glBegin(GL_LINE_LOOP);
glVertex2i(portals[0].viewport[0], portals[0].viewport[3]);
glVertex2i(portals[0].viewport[2], portals[0].viewport[3]);
glVertex2i(portals[0].viewport[2], portals[0].viewport[1]);
glVertex2i(portals[0].viewport[0], portals[0].viewport[1]);
glEnd();



here is an image of what i am getting as a result
gluproject><br><br><!--EDIT--><span class=editedby><!--/EDIT-->[Edited by - ih8lag on October 11, 2010 7:03:19 PM]<!--EDIT--></span><!--/EDIT-->

			
		</div>

		<div class='ipsItemControls'>
			
				
					

	<div data-controller='core.front.core.reaction' class='ipsItemControls_right ipsClearfix '>	
		<div class='ipsReact ipsPos_right'>
			
				<div class='ipsReact_reactCountOnly ipsAreaBackground_light ipsType_blendLinks ipsHide' data-role='reactCount'>
					
					0
					
				</div>
			
			
			
		</div>
	</div>


				
			
			<ul class='ipsComment_controls ipsClearfix ipsItemControls_left' data-role=
  • Share this post


    Link to post
    Share on other sites
    It has many issues:
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //!!!!!!!!!!


    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    SetYour3DProjectionHere();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    //!!!!!!!!!!!


    gluLookAt(0, 0, -1, 0, 0, 0, 0, 1, 0);

    double modl[16], proj[16], x, y, z;
    int view[4];

    glGetDoublev(GL_PROJECTION_MATRIX, &proj[0]);
    glGetDoublev(GL_MODELVIEW_MATRIX, &modl[0]);
    glGetIntegerv(GL_VIEWPORT, &view[0]);

    // project the portal points to the screen
    for(int j = 0; j < 2; j++)
    for(int i = 0; i < 4; i++)
    {
    gluProject(portals[j].points[i].x, portals[j].points[i].y, portals[j].points[i].z,
    modl, proj, view, &x, &y, &z);
    portals[j].ppoints[i].x = x;
    portals[j].ppoints[i].y = y;
    }

    // draw simulated portal to screen
    glColor3f(0, 1, 0);
    glBegin(GL_LINE_LOOP);
    glVertex3fv(&portals[0].ppoints[0].x);
    glVertex3fv(&portals[0].ppoints[1].x);
    glVertex3fv(&portals[0].ppoints[2].x);
    glVertex3fv(&portals[0].ppoints[3].x);
    glEnd();

    // draw projected coordinates
    //!!!!!!!!!

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D ( 0, 1024, 0, 768 );
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    //!!!!!!!!!!!!!


    glColor3f(1, 0, 0);
    glBegin(GL_LINE_LOOP);
    glVertex2i(portals[0].viewport[0], portals[0].viewport[3]);
    glVertex2i(portals[0].viewport[2], portals[0].viewport[3]);
    glVertex2i(portals[0].viewport[2], portals[0].viewport[1]);
    glVertex2i(portals[0].viewport[0], portals[0].viewport[1]);
    glEnd();


    Share this post


    Link to post
    Share on other sites

    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