[C#]OpenGL Application Semi tutorial

Newbie Spellweaver
Joined
Feb 22, 2008
Messages
23
Reaction score
0
So in reality, if you aren't familiar with English, don't bother to think to hard, just learn to use Google translator, because most of VB Code posted in here will be straight English, unless its invloving naming a Class.

Example of Naming a Class: class Coniki:Form
Explanation: Coniki is the name if the class you want to make under Form.

Purpose of tutorial: So you learn basic of OpenGL? Realize how easy it really is? Wonder why people make games all the time and you can't?

Tools:

A Mind (Very Important)
VC# 2008 (Use google to get it Google)
SDK DirectX10+ (Downloadable From Google and the various 10,000's of sites that house it Google)
Some Type of Focus (You need to be able to keep making mistakes and correcting them, you learn from doing wrong)
Inspiration (Without it your pretty much screwed)

First step in the tutorial is the hardest. You must find and add referneces to your project. WHY IS IT HARD? Cuz everyone forgets to do it!!

References used are
using System;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

Why these? OpenGL and its various forms mainly use these for basic function and error handling methods. Ultimately you can make your own Video Card Check, but it'll be based off these. In my tutorial I basically use a error message, standard and to the point, to alert uses of not only the error but to prompt them to take action.

A example is placed here for you to implement, but I did not include one in my own application. :P


{

MessageBox.Show(
null,
"Your too stupid to realize your GFX Card is Fucking Up "
+ e.Message, "Error");
Close();
}

Well the above part is pretty much in English, The message box pops up if the basic preset for the graphic card initialization isn't able to execute. It will then close the application after telling you, you are dumb, along with the error.

Instead if dissecting my tutorial into pieces, I'll place it in a clump, then break it down slowly. I want people to ask questions, so limited information will be given at first, and as questions arise along with concerns and optimized code, the tutorial will "evolve".

PHP:
    using System;
    using System.Windows.Forms;
    using Microsoft.DirectX;
    using Microsoft.DirectX.Direct3D;

     

    namespace ConikitikiIsHotzor
    {
       class MainClass:Form
       {
          private Device m_device = null;

     

          MainClass()
          {
             this.Text = "Coniki Triangle Tutorial";
          }

     

          void InitGraphics()
          {
             PresentParameters present_params = new PresentParameters();

             present_params.Windowed = true;
             present_params.SwapEffect = SwapEffect.Discard;

     

             m_device = new Device(0, DeviceType.Hardware, this,
                                   CreateFlags.SoftwareVertexProcessing, present_params);
          }

     

          protected override void OnPaint(PaintEventArgs e)
          {
             CustomVertex.TransformedColored[] vertexes = new CustomVertex.TransformedColored[3];

     

             vertexes[0].Position = new Vector4(50, 50, 0, 1.0f);
             vertexes[0].Color = System.Drawing.Color.FromArgb(0, 255, 0).ToArgb();
             vertexes[1].Position = new Vector4(250, 50, 0, 1.0f);
             vertexes[1].Color = System.Drawing.Color.FromArgb(0, 0, 255).ToArgb();
             vertexes[2].Position = new Vector4(50, 250, 0, 1.0f);
             vertexes[2].Color = System.Drawing.Color.FromArgb(255, 0, 0).ToArgb();

     

             m_device.Clear(ClearFlags.Target, System.Drawing.Color.FromArgb(0, 0, 0).ToArgb(), 1.0f, 0);
             m_device.BeginScene();        
             m_device.VertexFormat = CustomVertex.TransformedColored.Format;
             m_device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertexes);
             m_device.EndScene();
             m_device.Present();
          }

     

          static void Main()
          {
             MainClass MainForm = new MainClass();
             MainForm.InitGraphics();
             Application.Run(MainForm);
          }
       }
    }
Download my completed project below, and let me know if it works for you :P It includes the .PDB :O

WARNING AGAINST FLAMMERS: /IGNORE ON :D
 

Attachments

Last edited:
This indeed is the Very basics of OpenGL - I know that you've said 'I want people to ask questions, so limited information will be given at first'

But as this tutorial is indeed the very extreme basics of OpenGL in my personal opinion anybody not atleast slightly familiar with it will just see the code - And not have the SLIGHTEST clue about it at all. :tongue:

Also your namespace is badly named :tongue:

~ Jeax
 
actually ima add some information about the protected area of the code.

Protected Area: protected override void OnPaint only variables associated to OnPaint can access this part of the information, nothing else unless you set it to public. (As far as I know!)

BTW, yeah i know the namespace is bad, i don't suggest ppl use that namespace anyway, unless they really have no choice use namespace ConikiTikiIsHotzor (Fixed)

Flags: CreateFlags.SoftwareVertexProcessing We need to create a check for a current GFX Card. If it does not find a gfx card or somehow fails to intialize the check, we should report our error message and close the application immediately, if possible. The error message part is not included below, but it will be added later, we are going to evolve this bleak OpenGL object and transform it into a Bleach RPG Game. (Yes, I'm bored, but it's already been completed, decided that I too, wanted to try to make a semi decent game with this.)

A good example of this is check used here to check to see if the user has a video card in which we can manipulate to run our application. Mainipulate as in call to in order to construct specific data for the OpenGL application.

Caps DevCaps = D3D.Manager.GetDeviceCaps(0, D3D.DeviceType.Hardware);
CreateFlags DevFlags = CreateFlags.SoftwareVertexProcessing;
if (DevCaps.DeviceCaps.SupportsHardwareTransformAndLight)
{
DevFlags = CreateFlags.HardwareVertexProcessing;
}

That gfx card checking code was taken from DirectX 9 Tutorial using C#, C++ and Visual Basic > Checking Device caps

Remember to ask a bit more questions, so I can keep sharp on my toes, and also so I can continue this thread :D
 
Last edited:
opps, I got to fix a few things before i move on. ^^ Just a reminder, I've said it before I'll say it again, in no way am i uber elite programmer, I know enough to make my own applications.
 
I'm still learning full OpenGL on C# and most of the guides and pdf i researched say this bit is open gl based. You want to make a good arguement, go to the debate section and add, Why do guides say its Open GL and really its just DirectX. My mastery of C# is only 50%, can write and understand most syntax, can make basic to moderate applications. You forget that I stated im still learning working on this, will get better as i go and have more time. Go pick apart another tutorial or you could make your own tutorial, or pm me with a correct guide showing OpenGL instead of just DirectX.

Just a thought maybe, maybe not depends on how much time you have,since you had enough time to keep coming back to my thread...

Gonna post some videos soon of my work with "DirectX" working on VC# 2005. :D
 
Back