jsbsudha
asked on
Csharp Csgl error message
The following program is taken from nehe tutorial C sharp using csgl.... It shows a error message in the statement
base.onsizechanged
could anyone solve this error
base.onsizechanged
could anyone solve this error
what error? can you paste it?
ASKER
/* Lesson 05 of NeHe Productions in C#
created by Sabine Felsinger*/
using System;
using System.Windows.Forms;
using System.Drawing;
using CsGL.OpenGL;
namespace lesson05
{
public class OurView : OpenGLControl
{
public float rtri; // rtri is for rotating the pyramid
public float rquad; // rquad is for rotating the quad
public bool finished;
public OurView() : base()
{
this.KeyDown += new KeyEventHandler(OurView_On KeyDown);
finished = false;
}
protected void OurView_OnKeyDown(object Sender, KeyEventArgs kea)
{
//if escape was pressed exit the application
if (kea.KeyCode == Keys.Escape)
{
finished = true;
}
}
public override void glDraw()
{
GL.glClear(GL.GL_COLOR_BUF FER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the Screen and the Depth Buffer
GL.glMatrixMode(GL.GL_MODE LVIEW); // Modelview Matrix
GL.glLoadIdentity(); // reset the current modelview matrix
GL.glTranslatef(-1.5f,0.0f ,-6.0f); // move 1.5 Units left and 6 Units into the screen
GL.glRotatef(rtri,0.0f,1.0 f,0.0f); // rotate the Pyramid on it's Y-axis
rtri+=0.2f; // rotation angle
GL.glBegin(GL.GL_TRIANGLES ); // start drawing a triangle, always counterclockside (top-left-right)
GL.glColor3f(1.0f,0.0f,0.0 f); // Red
GL.glVertex3f(0.0f,1.0f,0. 0f); // Top of Triangle (Front)
GL.glColor3f(0.0f,1.0f,0.0 f); // green
GL.glVertex3f(-1.0f,-1.0f, 1.0f); // left of Triangle (front)
GL.glColor3f(0.0f,0.0f,1.0 f); // blue
GL.glVertex3f(1.0f,-1.0f,1 .0f); // right of triangle (front)
GL.glColor3f(1.0f,0.0f,0.0 f); // red
GL.glVertex3f(0.0f,1.0f,0. 0f); // top of triangle (right)
GL.glColor3f(0.0f,0.0f,1.0 f); // blue
GL.glVertex3f(1.0f,-1.0f,1 .0f); // left of triangle (right)
GL.glColor3f(0.0f,1.0f,0.0 f); // green
GL.glVertex3f(1.0f,-1.0f,- 1.0f); // right of triangel (right)
GL.glColor3f(1.0f,0.0f,0.0 f); // red
GL.glVertex3f(0.0f,1.0f,0. 0f); // top of triangle (back)
GL.glColor3f(0.0f,1.0f,0.0 f); // green
GL.glVertex3f(1.0f,-1.0f,- 1.0f); // left of triangle (back)
GL.glColor3f(0.0f,0.0f,1.0 f); // blue
GL.glVertex3f(-1.0f,-1.0f, -1.0f); // right of triangle (back)
GL.glColor3f(1.0f,0.0f,0.0 f); // red
GL.glVertex3f(0.0f,1.0f,0. 0f); // top of triangle (left)
GL.glColor3f(0.0f,0.0f,1.0 f); // blue
GL.glVertex3f(-1.0f,-1.0f, -1.0f); // left of triangle (left)
GL.glColor3f(0.0f,1.0f,0.0 f); // green
GL.glVertex3f(-1.0f,-1.0f, 1.0f); // right of triangle (left)
GL.glEnd();
GL.glLoadIdentity(); // reset the current modelview matrix
GL.glTranslatef(1.5f,0.0f, -7.0f); // move 1.5 Units right and 7 into the screen
GL.glRotatef(rquad,1.0f,1. 0f,1.0f); // rotate the quad on the X,Y and Z-axis
rquad-=0.15f; // rotation angle
GL.glBegin(GL.GL_QUADS); // start drawing a quad
GL.glColor3f(0.0f,1.0f,0.0 f); // green top
GL.glVertex3f(1.0f,1.0f,-1 .0f); // top right (top)
GL.glVertex3f(-1.0f,1.0f,- 1.0f); // top left (top)
GL.glVertex3f(-1.0f,1.0f,1 .0f); // bottom left (top)
GL.glVertex3f(1.0f,1.0f,1. 0f); // bottom right (top)
GL.glColor3f(1.0f,0.5f,0.0 f); // orange
GL.glVertex3f(1.0f,-1.0f,1 .0f); // top right (bottom)
GL.glVertex3f(-1.0f,-1.0f, 1.0f); // top left (bottom)
GL.glVertex3f(-1.0f,-1.0f, -1.0f); // bottom left (bottom)
GL.glVertex3f(1.0f,-1.0f,- 1.0f); // bottom right (bottom)
GL.glColor3f(1.0f,0.0f,0.0 f); // red
GL.glVertex3f(1.0f,1.0f,1. 0f); // top right (front)
GL.glVertex3f(-1.0f,1.0f,1 .0f); // top left (front)
GL.glVertex3f(-1.0f,-1.0f, 1.0f); // bottom left (front)
GL.glVertex3f(1.0f,-1.0f,1 .0f); // bottom right (front)
GL.glColor3f(1.0f,1.0f,0.0 f); // yellow
GL.glVertex3f(-1.0f,1.0f,- 1.0f); // top right (back)
GL.glVertex3f(1.0f,1.0f,-1 .0f); // top left (back)
GL.glVertex3f(1.0f,-1.0f,- 1.0f); // bottom left (back)
GL.glVertex3f(-1.0f,-1.0f, -1.0f); // bottom right (back)
GL.glColor3f(0.0f,0.0f,1.0 f); // blue
GL.glVertex3f(-1.0f,1.0f,1 .0f); // top right (left)
GL.glVertex3f(-1.0f,1.0f,- 1.0f); // top left (left)
GL.glVertex3f(-1.0f,-1.0f, -1.0f); // bottom left (left)
GL.glVertex3f(-1.0f,-1.0f, 1.0f); // bottom right (left)
GL.glColor3f(1.0f,0.0f,1.0 f); // violett
GL.glVertex3f(1.0f,1.0f,-1 .0f); // top right (right)
GL.glVertex3f(1.0f,1.0f,1. 0f); // top left (right)
GL.glVertex3f(1.0f,-1.0f, 1.0f); // bottom left (right)
GL.glVertex3f(1.0f,-1.0f,- 1.0f); // bottom right (right)
GL.glEnd();
}
protected override void InitGLContext()
{
GL.glShadeModel(GL.GL_SMOO TH); // enable smooth shading
GL.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // black background
GL.glClearDepth(1.0f); // depth buffer setup
GL.glEnable(GL.GL_DEPTH_TE ST); // enables depth testing
GL.glDepthFunc(GL.GL_LEQUA L); // type of depth test
GL.glHint(GL.GL_PERSPECTIV E_CORRECTI ON_HINT, GL.GL_NICEST); // nice perspective calculations
//rtri = 30.0f; define the rotation angle in the start position of the triangle
//rquad = 30.0f; define the rotation angle in the start position of the quad
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
Size s = Size;
GL.glMatrixMode(GL.GL_PROJ ECTION);
GL.glLoadIdentity();
GL.gluPerspective(45.0f, (double)s.Width /(double) s.Height, 0.1f, 100.0f);
GL.glMatrixMode(GL.GL_MODE LVIEW);
GL.glLoadIdentity();
}
}
public class MainForm : System.Windows.Forms.Form
{
private lesson05.OurView view;
public MainForm()
{
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(640, 480);
this.Name = "MainForm";
this.Text = "NeHe lesson 05 in C# (by Sabine Felsinger)";
this.view = new lesson05.OurView();
this.view.Parent = this;
this.view.Dock = DockStyle.Fill; // Will fill whole form
this.Show();
}
static void Main()
{
MainForm form = new MainForm();
while ((!form.view.finished) && (!form.IsDisposed)) // refreshing the window, so it rotates
{
form.view.glDraw();
form.Refresh();
Application.DoEvents();
}
form.Dispose();
}
}
}
created by Sabine Felsinger*/
using System;
using System.Windows.Forms;
using System.Drawing;
using CsGL.OpenGL;
namespace lesson05
{
public class OurView : OpenGLControl
{
public float rtri; // rtri is for rotating the pyramid
public float rquad; // rquad is for rotating the quad
public bool finished;
public OurView() : base()
{
this.KeyDown += new KeyEventHandler(OurView_On
finished = false;
}
protected void OurView_OnKeyDown(object Sender, KeyEventArgs kea)
{
//if escape was pressed exit the application
if (kea.KeyCode == Keys.Escape)
{
finished = true;
}
}
public override void glDraw()
{
GL.glClear(GL.GL_COLOR_BUF
GL.glMatrixMode(GL.GL_MODE
GL.glLoadIdentity(); // reset the current modelview matrix
GL.glTranslatef(-1.5f,0.0f
GL.glRotatef(rtri,0.0f,1.0
rtri+=0.2f; // rotation angle
GL.glBegin(GL.GL_TRIANGLES
GL.glColor3f(1.0f,0.0f,0.0
GL.glVertex3f(0.0f,1.0f,0.
GL.glColor3f(0.0f,1.0f,0.0
GL.glVertex3f(-1.0f,-1.0f,
GL.glColor3f(0.0f,0.0f,1.0
GL.glVertex3f(1.0f,-1.0f,1
GL.glColor3f(1.0f,0.0f,0.0
GL.glVertex3f(0.0f,1.0f,0.
GL.glColor3f(0.0f,0.0f,1.0
GL.glVertex3f(1.0f,-1.0f,1
GL.glColor3f(0.0f,1.0f,0.0
GL.glVertex3f(1.0f,-1.0f,-
GL.glColor3f(1.0f,0.0f,0.0
GL.glVertex3f(0.0f,1.0f,0.
GL.glColor3f(0.0f,1.0f,0.0
GL.glVertex3f(1.0f,-1.0f,-
GL.glColor3f(0.0f,0.0f,1.0
GL.glVertex3f(-1.0f,-1.0f,
GL.glColor3f(1.0f,0.0f,0.0
GL.glVertex3f(0.0f,1.0f,0.
GL.glColor3f(0.0f,0.0f,1.0
GL.glVertex3f(-1.0f,-1.0f,
GL.glColor3f(0.0f,1.0f,0.0
GL.glVertex3f(-1.0f,-1.0f,
GL.glEnd();
GL.glLoadIdentity(); // reset the current modelview matrix
GL.glTranslatef(1.5f,0.0f,
GL.glRotatef(rquad,1.0f,1.
rquad-=0.15f; // rotation angle
GL.glBegin(GL.GL_QUADS); // start drawing a quad
GL.glColor3f(0.0f,1.0f,0.0
GL.glVertex3f(1.0f,1.0f,-1
GL.glVertex3f(-1.0f,1.0f,-
GL.glVertex3f(-1.0f,1.0f,1
GL.glVertex3f(1.0f,1.0f,1.
GL.glColor3f(1.0f,0.5f,0.0
GL.glVertex3f(1.0f,-1.0f,1
GL.glVertex3f(-1.0f,-1.0f,
GL.glVertex3f(-1.0f,-1.0f,
GL.glVertex3f(1.0f,-1.0f,-
GL.glColor3f(1.0f,0.0f,0.0
GL.glVertex3f(1.0f,1.0f,1.
GL.glVertex3f(-1.0f,1.0f,1
GL.glVertex3f(-1.0f,-1.0f,
GL.glVertex3f(1.0f,-1.0f,1
GL.glColor3f(1.0f,1.0f,0.0
GL.glVertex3f(-1.0f,1.0f,-
GL.glVertex3f(1.0f,1.0f,-1
GL.glVertex3f(1.0f,-1.0f,-
GL.glVertex3f(-1.0f,-1.0f,
GL.glColor3f(0.0f,0.0f,1.0
GL.glVertex3f(-1.0f,1.0f,1
GL.glVertex3f(-1.0f,1.0f,-
GL.glVertex3f(-1.0f,-1.0f,
GL.glVertex3f(-1.0f,-1.0f,
GL.glColor3f(1.0f,0.0f,1.0
GL.glVertex3f(1.0f,1.0f,-1
GL.glVertex3f(1.0f,1.0f,1.
GL.glVertex3f(1.0f,-1.0f, 1.0f); // bottom left (right)
GL.glVertex3f(1.0f,-1.0f,-
GL.glEnd();
}
protected override void InitGLContext()
{
GL.glShadeModel(GL.GL_SMOO
GL.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // black background
GL.glClearDepth(1.0f); // depth buffer setup
GL.glEnable(GL.GL_DEPTH_TE
GL.glDepthFunc(GL.GL_LEQUA
GL.glHint(GL.GL_PERSPECTIV
//rtri = 30.0f; define the rotation angle in the start position of the triangle
//rquad = 30.0f; define the rotation angle in the start position of the quad
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
Size s = Size;
GL.glMatrixMode(GL.GL_PROJ
GL.glLoadIdentity();
GL.gluPerspective(45.0f, (double)s.Width /(double) s.Height, 0.1f, 100.0f);
GL.glMatrixMode(GL.GL_MODE
GL.glLoadIdentity();
}
}
public class MainForm : System.Windows.Forms.Form
{
private lesson05.OurView view;
public MainForm()
{
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(640, 480);
this.Name = "MainForm";
this.Text = "NeHe lesson 05 in C# (by Sabine Felsinger)";
this.view = new lesson05.OurView();
this.view.Parent = this;
this.view.Dock = DockStyle.Fill; // Will fill whole form
this.Show();
}
static void Main()
{
MainForm form = new MainForm();
while ((!form.view.finished) && (!form.IsDisposed)) // refreshing the window, so it rotates
{
form.view.glDraw();
form.Refresh();
Application.DoEvents();
}
form.Dispose();
}
}
}
ASKER
Exception error in the statement
base.OnSizeChanged(e);
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
Size s = Size;
GL.glMatrixMode(GL.GL_PROJ ECTION);
GL.glLoadIdentity();
GL.gluPerspective(45.0f, (double)s.Width /(double) s.Height, 0.1f, 100.0f);
GL.glMatrixMode(GL.GL_MODE LVIEW);
GL.glLoadIdentity();
}
base.OnSizeChanged(e);
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
Size s = Size;
GL.glMatrixMode(GL.GL_PROJ
GL.glLoadIdentity();
GL.gluPerspective(45.0f, (double)s.Width /(double) s.Height, 0.1f, 100.0f);
GL.glMatrixMode(GL.GL_MODE
GL.glLoadIdentity();
}
and which exception? "division by zero"? if yes, check that "s.Height" is not zero in protected override void OnSizeChanged(EventArgs e)
ASKER
please wait I will check it by opening my file
ASKER
type initialization exception was hadled in the statement base.onchanged(e)
ASKER
I am running the above Csharp program in VS2005 ....I am getting the error message as
Type initialiazation exception for csgl.OSLib unhanled
Type initialiazation exception for csgl.OSLib unhanled
can you show the code of base.onchanged(e) and the line the exception was thrown?
ASKER
the jpg file
pic.jpg
pic.jpg
can you click "view detail" and post it here?
ASKER
view details
pic2.jpg
pic2.jpg
it says: "the dll csgl.native.dll could not be found"
did you install csgl properly?
did you install csgl properly?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Could you tell me the exact procedure what I have to do
to install csgl in your project
to install csgl in your project
post-overlapping .. check my last comment ;)