protected override void InitGLContext()
{
GL.glClearColor( 1.0f, 1.0f, 1.0f, 0.0f );
GL.glColor3f( 0.0f, 0.0f, 0.0f );
GL.glPointSize( 4.0f );
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
GL.glMatrixMode(GL.GL_PROJECTION);
GL.glLoadIdentity();
GL.glOrtho( 0.0, Size.Width, 0.0, Size.Height, 1.0, -1.0 );
}
public override void glDraw()
{
GL.glRotatef(1.0f, 1.0f, 1.0f, 0.0f);
drawAxis();
}
private void drawAxis()
{
double left = 0.05 * Size.Width;
double right = 0.95 * Size.Width;
double bottom = 0.05 * Size.Height;
double top = 0.95 * Size.Height;
double origin_x = Size.Width / 2;
double origin_y = Size.Height / 2;
// draw X axis
GL.glBegin( GL.GL_LINES );
GL.glVertex3d( left, origin_x, 0 );
GL.glVertex3d( right, origin_x, 0 );
GL.glEnd();
// draw Y axis
GL.glBegin( GL.GL_LINES );
GL.glVertex3d( origin_y, bottom, 0 );
GL.glVertex3d( origin_y, top, 0 );
GL.glEnd();
// draw Z axis
GL.glBegin( GL.GL_LINES );
GL.glVertex3d( origin_x, origin_y, 0.0 );
GL.glVertex3d( origin_x, origin_y, 1.0 );
GL.glEnd();
GL.glFlush();
}
Need quick help with OpenGL glRotate!
I am writing an app in C# (VS.NET). I am using CsGL for some basic OpenGL stuff. I want to draw an x,y, and z axes in the control, and then rotate the view so that it looks 3D - if you draw the axes and don't rotate them, you wouldn't be able to see the Z axis.
Here's my code, which I based mainly on (http://www.componentsnotebook.com/notebooks/csharp/csgl.aspx). You will see that I called GL.glRotatef(1.0f, 1.0f, 1.0f, 0.0f); at one point. I picked 1.0 for the angle arbitrarily; however, no matter what angle I choose, it only seems to make the axes smaller. Please help, and if there are any questions ask away!
Are you setting the matrix mode back to whatever it was before you changed it, which was likely GL_MODELVIEW?
quote:Original post by smart_idiot
Are you setting the matrix mode back to whatever it was before you changed it, which was likely GL_MODELVIEW?
Well I''m new to OpenGL, so I''m really not sure what you''re asking or what I have to do. The code I''m showing is everything that deals with OpenGL, so what you see is what you get. Could you explain what I should be doing? Thanks!
Okay. . .
In OpenGL whenever you change something, it stays that way until you change it again. That includes colours, the matricies, and pretty much everything else.
If you don''t change back to the modelview matrix, then you will end up rotating the projection matrix, which isn''t what you wanted.
So basically what I''m saying is to change the function OnSizeChanged to this:
In OpenGL whenever you change something, it stays that way until you change it again. That includes colours, the matricies, and pretty much everything else.
If you don''t change back to the modelview matrix, then you will end up rotating the projection matrix, which isn''t what you wanted.
So basically what I''m saying is to change the function OnSizeChanged to this:
protected override void OnSizeChanged(EventArgs e){ base.OnSizeChanged(e); GL.glMatrixMode(GL.GL_PROJECTION); GL.glLoadIdentity(); GL.glOrtho( 0.0, Size.Width, 0.0, Size.Height, 1.0, -1.0 ); GL.glMatrixMode(GL.GL_MODELVIEW);}
Perhaps these images will help explain my problem.
The following is the picture of the unrotated axes:
http://www.terptrader.com/normalaxis.png
........
When I include the glRotate function:
I get the following image:
http://www.terptrader.com/rotatedaxis.png
Can anyone explain to me what is going on? My goal is to have the axes look 3D, like in this picture: http://wonkosite.ausbone.net/vrml/axis.gif
[edited by - mshafrir on July 7, 2003 3:03:52 PM]
public override void glDraw() { //GL.glRotatef(10f, 0.71f, 0.71f, 0); drawAxis(); }
The following is the picture of the unrotated axes:
http://www.terptrader.com/normalaxis.png
........
When I include the glRotate function:
public override void glDraw() { GL.glRotatef(10f, 0.71f, 0.71f, 0); drawAxis(); }
I get the following image:
http://www.terptrader.com/rotatedaxis.png
Can anyone explain to me what is going on? My goal is to have the axes look 3D, like in this picture: http://wonkosite.ausbone.net/vrml/axis.gif
[edited by - mshafrir on July 7, 2003 3:03:52 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement