Hase's picture

How to draw stuff with Tao / native openGl *like* code?

Hey, im new to openTK and hoped that i can use normal openGl like syntax instead of the .net optimized one.
Since i want to port alot stuff that i wrote in other languages with openGL over to c#, and also i like the way openGL handles stuff more.

so i just cropped down a sample and tried to just use some tao code within it, but i dont see anything.

i just did this tutorial as test:
http://nehe.gamedev.net/tutorial/adding_colour/13003/

and thats my code for now:
(its on windows, visual studio)

(its running fine and stuff but i cant see anything)
did i just forgot something that i need to do with tao?
(i never used tao ...)

using System;
using System.Drawing;
using System.Diagnostics;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input;
using Tao.OpenGl;
 
namespace test {
 
  public class Game :GameWindow {
 
    // constructior fürs game type
    public Game():base(800, 600) {//, GraphicsMode.Default, "dings") {        
 
    }
 
    // key event handle stuff
    void Keyboard_KeyDown(object sender, KeyboardKeyEventArgs e) {
      if(e.Key == Key.Escape) { Exit(); }
    }
 
    //ditte hier wird wohl ausgeführt wenn das openGL control geladen wird.
    protected override void OnLoad(EventArgs e) {
      // events, init stuff etc hier.    
      Keyboard.KeyDown += new EventHandler<KeyboardKeyEventArgs>(Keyboard_KeyDown); ;
    }
 
    protected override void OnResize(EventArgs e) {
      //event das beim beim größe ändern des fensters gerotzt wird
      // wohl nett für neue projection matrix dann und so
    }
 
    protected override void OnUpdateFrame(FrameEventArgs e) {
      base.OnUpdateFrame(e);
      Debug.Print("update");
    }
 
    protected override void OnRenderFrame(FrameEventArgs e) {
      // draw stuff hier  
      base.OnRenderFrame(e);
      // hab als test einfach mal ein nehe tutorial eingefügt
 
      Debug.Print("render");      
 
      Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
      Gl.glLoadIdentity();                   // Reset The Current Modelview Matrix
      Gl.glTranslatef(-1.5f, 0.0f, -6.0f);  // Left 1.5 Then Into Screen Six Units
 
      Gl.glBegin(Gl.GL_TRIANGLES);                  // Begin Drawing Triangles
 
      Gl.glColor3f(1.0f, 0.0f, 0.0f);          // Set The Color To Red
      Gl.glVertex3f(0.0f, 1.0f, 0.0f);          // Move Up One Unit From Center (Top Point)
 
      Gl.glColor3f(0.0f, 1.0f, 0.0f);          // Set The Color To Green
      Gl.glVertex3f(-1.0f, -1.0f, 0.0f);          // Left And Down One Unit (Bottom Left)
 
      Gl.glColor3f(0.0f, 0.0f, 1.0f);          // Set The Color To Blue
      Gl.glVertex3f(1.0f, -1.0f, 0.0f);          // Right And Down One Unit (Bottom Right)
 
      Gl.glEnd();                        // Done Drawing A Triangle
 
      SwapBuffers(); // its like flip() ?
    }
 
    [STAThread]
    public static void Main() {
      using(Game game = new Game()) {
        game.Run(60d, 30d); 
      }
    }
  }
}

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
dvdking's picture

I think you forgot to specify viewport

GL.Viewport(0, 0, 800, 600);