Jump to content
  • Advertisement
Sign in to follow this  
ih8lag

gluproject

This topic is 2809 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 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.x, portals[j].points.y, portals[j].points.z,
modl, proj, view, &x, &y, &z);
portals[j].ppoints.x = x;
portals[j].ppoints.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'>
					
					<span data-role='reactCountText'>0</span>
					
				</div>
			
			
			
		</div>
	</div>

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


    Link to post
    Share on other sites
    Advertisement
    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.x, portals[j].points.y, portals[j].points.z,
    modl, proj, view, &x, &y, &z);
    portals[j].ppoints.x = x;
    portals[j].ppoints.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
    Sign in to follow this  

    • Advertisement
    ×

    Important Information

    By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

    Participate in the game development conversation and more when you create an account on GameDev.net!

    Sign me up!