Link to home
Start Free TrialLog in
Avatar of jsbsudha
jsbsudhaFlag for Germany

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
Avatar of ikework
ikework
Flag of Germany image

what error? can you paste it?
Avatar of jsbsudha

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_OnKeyDown);
                  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_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);      // Clear the Screen and the Depth Buffer
                  GL.glMatrixMode(GL.GL_MODELVIEW);            // 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.0f,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.0f);                  // Red
                  GL.glVertex3f(0.0f,1.0f,0.0f);                  // Top of Triangle (Front)
                  GL.glColor3f(0.0f,1.0f,0.0f);                  // green
                  GL.glVertex3f(-1.0f,-1.0f,1.0f);            // left of Triangle (front)
                  GL.glColor3f(0.0f,0.0f,1.0f);                  // blue
                  GL.glVertex3f(1.0f,-1.0f,1.0f);                  // right of triangle (front)

                  GL.glColor3f(1.0f,0.0f,0.0f);                  // red
                  GL.glVertex3f(0.0f,1.0f,0.0f);                  // top of triangle (right)
                  GL.glColor3f(0.0f,0.0f,1.0f);                  // blue
                  GL.glVertex3f(1.0f,-1.0f,1.0f);                  // left of triangle (right)
                  GL.glColor3f(0.0f,1.0f,0.0f);                  // green
                  GL.glVertex3f(1.0f,-1.0f,-1.0f);            // right of triangel (right)

                  GL.glColor3f(1.0f,0.0f,0.0f);                  // red
                  GL.glVertex3f(0.0f,1.0f,0.0f);                  // top of triangle (back)
                  GL.glColor3f(0.0f,1.0f,0.0f);                  // green
                  GL.glVertex3f(1.0f,-1.0f,-1.0f);            // left of triangle (back)
                  GL.glColor3f(0.0f,0.0f,1.0f);                  // blue
                  GL.glVertex3f(-1.0f,-1.0f,-1.0f);            // right of triangle (back)

                  GL.glColor3f(1.0f,0.0f,0.0f);                  // red
                  GL.glVertex3f(0.0f,1.0f,0.0f);                  // top of triangle (left)
                  GL.glColor3f(0.0f,0.0f,1.0f);                  // blue
                  GL.glVertex3f(-1.0f,-1.0f,-1.0f);            // left of triangle (left)
                  GL.glColor3f(0.0f,1.0f,0.0f);                  // 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.0f);                  // 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.0f);                  // 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.0f);                  // 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.0f);                        // 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.0f);                  // 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.0f);                  // 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_SMOOTH);                                                // 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_TEST);                                                // enables depth testing
                  GL.glDepthFunc(GL.GL_LEQUAL);                                                // type of depth test
                  GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_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_PROJECTION);
                  GL.glLoadIdentity();
                  GL.gluPerspective(45.0f, (double)s.Width /(double) s.Height, 0.1f, 100.0f);      
                  GL.glMatrixMode(GL.GL_MODELVIEW);
                  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();
            }
      }
}
Exception error in the statement

base.OnSizeChanged(e);

protected override void OnSizeChanged(EventArgs e)
            {
                  base.OnSizeChanged(e);
                  Size s = Size;

                  GL.glMatrixMode(GL.GL_PROJECTION);
                  GL.glLoadIdentity();
                  GL.gluPerspective(45.0f, (double)s.Width /(double) s.Height, 0.1f, 100.0f);      
                  GL.glMatrixMode(GL.GL_MODELVIEW);
                  GL.glLoadIdentity();
            }
and which exception?  "division by zero"? if yes, check that "s.Height" is not zero in protected override void OnSizeChanged(EventArgs e)
please wait I will check it by opening my file
type initialization exception was hadled in the statement  base.onchanged(e)
I am running the above Csharp program in  VS2005 ....I am getting the error message as

Type initialiazation exception for csgl.OSLib unhanled
can you show the code of base.onchanged(e) and the line the exception was thrown?
the jpg file
pic.jpg
can you click "view detail" and post it here?
view details
pic2.jpg
it says: "the dll csgl.native.dll could not be found"

did you install csgl properly?
ASKER CERTIFIED SOLUTION
Avatar of ikework
ikework
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Could you tell me the exact procedure what I have to do
to install csgl in your project
post-overlapping .. check my last comment ;)