Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


New to OpenGL, some issues


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Erithtotl   Members   -  Reputation: 106

Like
0Likes
Like

Posted 24 October 2013 - 02:00 PM

I am new to OpenGL (and graphics programming in general).

 

I am working through Daniel Schuller's 'C# Game Programming for Serious Game Creation'.

 

Some of the examples in the book are not behaving the way the book indicates.  I want to figure out if I am doing something wrong or the book is.

 

I have a simple rotating triangle method:

 

            float width=0.5;

            Gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
            Gl.glPointSize(5.0f);
 
            Gl.glRotated(_currentRotation, 0, 1, 0);
            Gl.glBegin(Gl.GL_TRIANGLE_STRIP);
            {
                Gl.glColor4d(1.0, 0.0, 0.0, 0.5);
                Gl.glVertex3d(-width, 0, 0);
                Gl.glColor3d(0.0, 1.0, 0.0);
                Gl.glVertex3d(width, 0, 0);
                Gl.glColor3d(0.0, 0.0, 1.0);
                Gl.glVertex3d(0, width, 0);
            }
            Gl.glEnd();
            Gl.glFinish();
 
 
 
I also have a Setup2DGraphics function that gets called on startup and everytime the host form changes size:
 
        private void Setup2DGraphics(double width, double height)
        {
            Gl.glViewport(0, 0, (int)width, (int)height);
            double halfWidth = width / 2;
            double halfHeight = height / 2;
            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            Gl.glOrtho(-halfWidth, halfWidth, -halfHeight, halfHeight, -100, 100);
            Gl.glMatrixMode(Gl.GL_MODELVIEW);
            Gl.glLoadIdentity();
 
        }
 
 
The problem I am having is that no matter what size I change the form to, it seems like the Triangle is being drawn to an openGL space that is -1,1,-1,1.
 
That is, if I set width on the triangle to 0.5, then I get a triangle that stretches up, left and right half the viewport size.
 
My understanding (and the way the book presents it) is that if I'm passing in the height and width of the form to Setup2DGraphics function, (using ClientSize.Height and ClientSize.Width properties), that glOrtho will essentially make a 1:1 mapping between the viewport and my form.  But that is not happening.  No matter the size of the form, the triangle scales to the window size even as the width stays constant at 0.5.  If I make width, say, 50, then it stretches vastly off the viewport.
 
So what am I missing/doing wrong here?
 
Thanks in advance!


Sponsor:

#2 Brother Bob   Moderators   -  Reputation: 8454

Like
0Likes
Like

Posted 24 October 2013 - 02:27 PM

The obvious cause of the described effect is that the projection matrix isn't set. Common reasons are because the setup function isn't called, it is called before the window and the rendering context is created, or because the projection matrix is reset at some later point.


Edited by Brother Bob, 24 October 2013 - 02:28 PM.


#3 Erithtotl   Members   -  Reputation: 106

Like
0Likes
Like

Posted 24 October 2013 - 02:36 PM

The obvious cause of the described effect is that the projection matrix isn't set. Common reasons are because the setup function isn't called, it is called before the window and the rendering context is created, or because the projection matrix is reset at some later point.

I think you are right.  I've done some experimenting and it seems that is what is happening.  I'll figure out why.

 

Thanks!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS