Results 1 to 7 of 7

Thread: Error changing projection matrix?

  1. #1
    Member Contributor
    Join Date
    Oct 2011
    Posts
    72

    Error changing projection matrix?

    Hi,

    I'm trying to draw a rectangle in a perspective projection to show the area selected by the user when he wants to select the objects inside the rectangle drawn but the rectangle is not shown.

    Here's the code.

    Code :
    public void DrawRectangleSelection(Point point1, Point point2)
    {
    	// Store the projection matrix
    	Gl.glMatrixMode(Gl.GL_PROJECTION);
    	Gl.glPushMatrix();
    	Gl.glLoadIdentity();
    	// Change the projection to orthographic
    	Gl.glOrtho(-20, 20, -20, 20, -50, 50);
    	Gl.glMatrixMode(Gl.GL_MODELVIEW);
    	Gl.glPushMatrix();
    	Gl.glLoadIdentity();
    	// Draw the rectangle
    	Vector3d wp1 = UnProject(point1.X, point1.Y, 0);
    	Vector3d wp2 = UnProject(point2.X, point2.Y, 0);
     
    	Gl.glVertex3d(wp1.X, wp1.Y, 0);
    	Gl.glVertex3d(wp1.X, wp2.Y, 0);
    	Gl.glVertex3d(wp2.X, wp2.Y, 0);
    	Gl.glVertex3d(wp2.X, wp1.Y, 0);
    	// Restore the Projection matrix
    	Gl.glMatrixMode(Gl.GL_PROJECTION);
    	Gl.glPopMatrix();
    	// Restore the ModelView matrix
    	Gl.glMatrixMode(Gl.GL_MODELVIEW);
    	Gl.glPopMatrix();
    }

    There's some extra code before the method is called that calls the glBegin(), and so on.

    The custom method UnProject() works well.

    Do I've some error in my code? I suspect I've an error changing the projection matrix.

    Thanks

    PD: I'm using TAO Framework.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    171

    Re: Error changing projection matrix?

    can you use
    gluOrtho2D
    i m not sure but -50, 50);
    may cause some problem
    may be use gluOrtho2D
    and read gluOrtho2D spec
    read
    if u don't know gluOrtho2D.
    haven't made a game [img]<<GRAEMLIN_URL>>/frown.gif[/img]

  3. #3
    Senior Member Regular Contributor
    Join Date
    Dec 2008
    Location
    USA
    Posts
    134

    Re: Error changing projection matrix?

    You need Gl.glBegin(GL_QUADS), or some other primitive type before you call glVertex*, and a glEnd() afterwards.

  4. #4
    Senior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    171

    Re: Error changing projection matrix?

    damn,
    i haven't notice
    haven't made a game [img]<<GRAEMLIN_URL>>/frown.gif[/img]

  5. #5
    Member Contributor
    Join Date
    Oct 2011
    Posts
    72

    Re: Error changing projection matrix?

    Hi Todayman,

    In my post I wrote:

    There's some extra code before the method is called that calls the glBegin(), and so on.

  6. #6
    Senior Member Regular Contributor
    Join Date
    Dec 2008
    Location
    USA
    Posts
    134

    Re: Error changing projection matrix?

    Didn't notic that, but...

    The glBegin() and end must be immediately around the glVertex commands. Matrix manipulation commands are not allowed to be between the glBegin and glEnd. When you call these function, OpenGL is probably getting an error and ignoring the primitives defined by that begin/end block.

    Only normal, texture coordinate, color, attribute, and fog settings (which are per-vertex) can be set within the block.

  7. #7
    Member Contributor
    Join Date
    Oct 2011
    Posts
    72

    Re: Error changing projection matrix?

    Hi Todayman!

    That's exactly what's happening glBegin() must be immediately around the glVertex().

    Now it works!

    Thank you guys

Similar Threads

  1. Replies: 0
    Last Post: 09-16-2015, 03:27 PM
  2. Updating projection matrix after changing viewport aspect ratio
    By madmax1 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 06-03-2014, 01:22 PM
  3. Using modelview/projection matrix to do a projection myself
    By AllForum in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 08-30-2012, 07:42 AM
  4. Projection matrix, arbitrary projection plane
    By omdown in forum OpenGL: General
    Replies: 0
    Last Post: 04-01-2010, 07:26 AM
  5. Can concatenate projection matrix with viewport transformation matrix?
    By MelvinEng in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 07-07-2002, 10:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean