lid6j86's picture

Open TK Beginning

So I've been struggling through my first efforts to use OpenTK, and I thought perhaps writting my progress down would both help me and perhaps benefit others who may be having similar problems. I'm almost positive my ways are not necessarily the most efficient, but I'm not going to worry about that for now.

Right now the biggest thing I'm having problems with is textures, but I'll start from the beginning.

First, I have to say that graphics programming and app programming are two radically different things. I've programmed various basic apps for a while, but coming into the graphics world taught me the most valuable lesson anyone can really learn: I am a complete beginner when it comes to programming and I know nothing. Might seem like standard logic there, but when you get into a routine of programming the type of things you have familiarized yourself with (for me it was databases, ciphers, etc...) and dont try to expand, you really end up feeling like you a professional-level, technically competant programmer. So there's my lesson, I have a long way to go. I have never struggled through coding this much. There are a lot of unique concepts, and a lot of rituals and specific steps that, once learned, will be routine and commonplace, but to an outsider looking in it can be overwheleming.

When I look at code and examples, I don't like to see extra 'fluff'. by that, I mean I dont like to see optimized code, shortcut variables, and no comments. I've always felt examples are poorly explained and don't completely bridge the gap from a new person to a competant and capable person. When I say i don't like to see optimized code, I don't mean that I don't like it at all, it has a time and place, and it's great (and sometimes necessary) to learn. But when I'm trying to grasp the concepts for the first time, I don't need to see it. I'm more concerned with getting something onto the screen at all, rather than loading all kinds of buffers that a first program will never use (even if you might use them in later programs).

That having been said, my first program (i'm ashamed to say) took me an hour to figure out how to even initialize a screen properly. In all fairness, the books I am reading about OpenGL are all using GLUT and C++. I have one book that covers OpenGL in C# with TAO, which is the closest reference I have. It took me a while to figure out how to convert it because OpenTK is cleaned up. From one aspect, I'm glad it's cleaned up. From another aspect, I actually wish it weren't cleaned up so it is easier for me to learn (nearly) directly from the books. A lot of what these books are teaching become old messy techniques in OpenTK, and some of it is just unecessary. Take, for example, the lack of a need to initialize your GLControl, or even initializing a window at all.

Ultimately, we are all drawn together on to this site because of our love for programming, right? So I hope this can help the group (myself included because i'm certainly a straggler) stay together and move into a positive direction. What I'm going to ATTEMPT to do is read through the OpenGL SuperBible 4th Edition from Chapter 1 and translate it into OpenTK. Hopefully this helps me in the process.

There are a couple of classes that I got from the C# book that I use for things like looping, but the loop and precision timing are really the only ones I use (I'll post my code for them), but they call Windows APIs. There should be equivalents for anyone using MONO or something like that.

Anyways, that was my introduction, sorry for making it so long winded, but hopefully this will establish a good foundation. If any of the more experienced programmers would help me as I post the code up and either explain more efficient ways to do things, why a piece of code is not working, or how it works in OpenTK, it would be greatly appreciated. I'll try to post often, as the goal is to ultimately get a little practice in each night.


Comment viewing options

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

"When I look at code and examples, I don't like to see extra 'fluff'. by that, I mean I dont like to see optimized code, "

OpenTK is only opengl wrapper, no more, no less. What makes it easier to code (when comparing C++ opengl programming) is enums, you can only put variables what is available whatever method you use.
I think examples is good to start with, and had no problems to work with them. But if you have problems, tell to us, there is lots of people who (maybe) can help. :)

And which works with opengl, works of course with opentk.
(I did some practises myself too, and engine works with 1.5+ and 3.0 only which is still unoptimized , at least it works on my computer, and I dont work with that project anymore anyhow, jeah, and that project was csat)

But, specific questions, and you got some answers hopefully.

lid6j86's picture

(by the way, this post was not at all a slight against any of the material on the site, because it's fantastic and it's helped me immensely in understanding)

I guess the point is even with all of the material I've had to weed through a lot of the stuff to understand base components. I guess like they say, no pain no gain, but I hope that me going through this will maybe help others go through the stuff faster than I did. Most of this is for my own education :-)

lid6j86's picture

puklaus, I didn't mean to say OpenTK itself is 'optimized'. OpenTK is cleaned up a little in how you call the methods, but what I was referring to is that a lot of examples I've found on the internet (not just here) try to make you run without first teaching you how to walk. They go into how 'they' do it because it's 'faster, better, harder, stronger', but they don't really teach you the base components of what made it work in the first place before they teach you how to make it faster :-)

puklaus's picture

Check Nehe, the best place to learn opengl ( and tutorals on the right side).
It teaches opengl from the start. I dont think there is otk or c# code but quite easy to convert them to otk.

lid6j86's picture

thanks for the reference

flopoloco's picture

I started learning OpenGL in my free time in 2008 and just started getting warm up.
I think that in 1 more year I will have the essential knowledge to start my MMORPG game engine. :D

lid6j86's picture

yea i have 2 great ideas for games but i need to build myself up, so i keep coming up with more simple programs. I've been contemplating over the past 3 weeks what I will use for random terrain.

I was thinking a great way to get variable height would be to use sin waves. if you were able to get an xpattern sin wave and a ypattern sinewave, it should create variable 3d height. from there you could do a few more calculations in order to make it more interesting.

So far everything is just theory, i've yet to put any of it into practice