objarni's picture

Simple OpenTK/OpenAL example..?

I would like to play programmatically generated sine wave (or other waveform) through OpenTK.

1) Is it possible?
2) Does anybode have a GameWindow example of this?


Comment viewing options

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

uint bla = Alut.CreateBufferWaveform(AlutWaveform.Sine, 500f, 42f, 1.5f);

I admit it's a bit spaghetti due to the attempt to crunch as much info as possible into 1 page, but more info here:


objarni's picture

Thanks! I haven't read through all the AL docs yet, but it would be really nice with a minimal GameWindow code example just playing a single sound.

In this regard I think the Examples are a bit "overdone"; they do all this fancy interface stuff which "greys out" the real purpose of the example: to show how to do things in OpenTK.

Are there any plans to make "standalone, minimalistic" examples of key areas of OpenTK? I might be willing to create a few such examples myself, instead of always asking you guys to build things ;) If there is interest in this, that is!

the Fiddler's picture

Inertia has written a few examples on OpenAL, plus one on FBOs, but I haven't added them to SVN yet. If you have the time, we are always interested in more. Do you have any specific topics in mind?

Regarding the "Example Launcher", there's a practical reason for its existence: without it, every example would be a standalone exe/project, which would require too much upkeep while developing. I'm not sure what you mean by the 'interface stuff', but 0.9.1 will remove some of the noise: the examples will only need a single [Example] attribute to work. One more cool thing is that the examples can work as standalone applications, too (i.e. outside the launcher).

There's a big update coming that I think will increase the value of the launcher (I agree that its somewhat lacking right now): every example will come with a bundled tutorial, displayed inside the launcher. Moreover, the launcher will allow the user to edit the source code of any example, and see the results on the fly. (actually this part is already working, with only minor stuff remaining)

Edit: One more thing, OpenAL support is still somewhat raw/untested. It will get better over time. :)

objarni's picture

The update seems really nice! Seeing a tutorial and being able to edit and re-run would help tremendously in learning OpenTK! Great work :)

Some topics I'd like to see examples in:

1) Simple VBO usage (two-three triangles are perfect; more and it becomes unecessarily complex -- but Inertia seem to have covered this already)
2) Playing a sine wave ( no loading ! )
3) Loading WAV / other supported formats (don't know which are supported)
4) Loading and displaying an image over the screen
5) Displaying Hello World and responding to any key (exits)
6) Using Mouse (moving triangle or something)
7) Going into / out of Fullscreen
8) etc. etc. list could be made very long :)

For all examples, both GLControl and GameWindow are valuable (where appropriate -- I guess eg. OpenAL usage is the same. But Mouse/Keyboard might be different I guess..)

In general, I'm looking for usage examples, not technique examples. Technique I read in books / online / work out myself, but using-OpenTK-examples are really valuable. And it's simpler for beginners to work out simple things than complex things (I guess that is true for non-beginner too!)

Keep up the good work, OpenTK is really getting interesting!

the Fiddler's picture

1) Oh, the missing VBO example. Check the GLSL example at the moment, the VBO example is hidden due to some problems (press Ctrl-F1 to bring it up). Inertia has covered FBOs, not VBOs! ;)

2, 3) Will appear in SVN soon. Only waves are supported right now, but I'm looking into vorbis (there's a C# loader in Mono SVN, but it's slow and unsupported). There are some interesting things brewing over at the Banshee media player too, which might allow us to do more in the future (even mp3, maybe).

4) There's a "textures" example. New samples using Inertia's loaders will also appear at some point, soon.

I think we agree about the "usage examples, not techniques" part. There's a *lot* of stuff available on OpenGL out there, the important part is to show how to convert that to OpenTK.

Inertia's picture

I don't think we should bother with writing an equivalent to Alut.CreateBufferWaveform() for TKU.dll, if you have tried producing any sample with that function you will totally agree with me that it's not practical in any way, unless you are coding a commodore-64 emulator ;)

The number of tutorials/samples will inevitably grow over time, but OpenTK is still "under construction" and my experience from the book pages was that writing examples - before the API is locked down - requires updates to them aswell with version changes, so they should probably be kept to a minimum for now. Ok, the changes weren't radical, but the removal of VersionXY enums altered quite a bit. (not a complaint|whine, just stating the fact)

objarni's picture

If the examples are kept short and easy, the risk of having to alter them really much is kept at a minimum. Putting up examples of the latest and least stable APIs is a higher risk though, I agree. So I can see OpenAL as being one of the latter..

Why wouldn't I code a C64 emulator on steroids :)

cya around guys!

Inertia's picture

Because you'd have to be really, truely nostalgic to write the 1001st c64 emulator? :P

The OpenAL bindings themselves are done, there's nothing on the todo list for them - they even have CLS compliant overloads now, so that Fiddler is happy! I've ported 6 of the 10 OpenAL SDK samples to OpenTK and they all execute the same tasks as their C pendants without any problems. The other 4 samples make heavy use of custom .wav/.ogg file loading, which cannot be done before TKU.dll supplies the necessary functionality, but I see no problems with that because buffer creation is the only part where OpenAL touches unmanaged memory.

My point was, it is really too early to write samples for areas that are still under heavy construction (like the font classes), where it's pretty much guaranteed that the API will change. The way I understood it, OpenTK 1.0.0 will be the API lockdown (namespace, class and functions may not be altered anymore). The release candidates before the lockdown are the point where alot of tutorials/samples/bookpages will spawn, to verify that the lockdown is reasonable and the API is nice to use.

Atm Fiddler's todo list is longer than your arm, and please *please* don't try talking him into writing some apps that GL.Translates a quad with the mouse ;)

I might write a book page about pinning, if that is the problem in porting C apps to C#?

objarni's picture

Inertia: Don't worry, I'm not trying to convince Fiddler to write such examples, I'm trying to convince *you* to do it heh ;)

I understand the situation. Are there any OpenTK classes that have not changed the last four-five months..? Those would be candidates for example code.

Inertia's picture

....I think Properties/Assemblyinfo.cs was not changed for a while :p

Seriously, the only class that meets this requirement (and will most likely not be changed soon either) is OpenTK.Math.