Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Friday, June 16, 2017

OpenTK Example - FBO / Render Target TV

Available on Github

This is a small example of how to use a framebuffer object (sometimes the output is called a render target, although that's more of a DirectX term) in OpenTK. There's a second camera in the scene with its position indicated by the arrow. What that camera sees is put into a texture and then displayed on a model of a TV.



This is also significant because it allows us to get the depth information of the scene. This allows us to create shadows later by easily determining if there is an object closer to the light (which would have a camera "seeing" from its direction above or in the scene), and darkening parts where that is true.

Controls:

  • WASDQE - Move main camera
  • UHJK - Move texture camera
  • C - Switch between color view and depth view
  • V - Toggle TV static shader on/off

Friday, August 12, 2016

Update on next tutorial/example

Here's an update on what I have planned next.

I wanted to jump right into shadows next, but I realized that there's a few prerequisites before we get to that. One of those is rendering to a framebuffer/texture, and another is getting a depth map from another camera. So, next up is handling both of those. In addition, cube maps would be needed to handle shadows from point lights, so that's another topic to add.

However, my job is going to be picking up soon, and these require a lot of changes to the existing code that would take a lot of time to make as another tutorial in the series. Like before, I'm considering doing examples instead of tutorials here on out, so we can cover more topics in less time. The examples would still break down the new stuff, but they won't follow the process of adding it to the previous topic's project files.

Here the TV screen is showing the view from a second camera (the second camera is at the arrow)

Here it is rendering the depth information from the other camera

Friday, July 29, 2016

OpenTK Tutorial 9 Part 3: Specular Maps and Attenuation

In the previous part of this tutorial, we added spot lights and directional lights. This time, we're adding specular maps and light attenuation.


Tuesday, July 26, 2016

OpenTK Tutorial 9 Part 2: New Light Types (Spot and Directional)

In the first part of this tutorial, we made it possible to use more than one light in a scene. In this part of the tutorial, we'll be adding two new light types.

The next (and final) part of this tutorial will add specular mapping and attenuation.

Sunday, June 12, 2016

OpenTK Tutorial 9 Part 1: Multiple Lights

This will be the first part of our more advanced lighting arc. In this part, we'll allow the scene to have many lights instead of just one.

This next part will add two new types of light: spot lights that only shine in a limited cone, and directional lights that shine at a constant angle on the whole scene. A third part will add specular maps and attenuation, to make the lighting look a little more realistic.

Wednesday, April 27, 2016

Update on Next Tutorial

I wanted to give everyone an update on the next tutorial, since it's been a while.

As you can see in the pictures, there's multiple lights at once, specular maps (look at the difference between the land and ocean), and spot lights. This code also includes directional lighting, but I think it didn't make the pictures.

I'm sorry to let this take so long. Life has been busy, but it should be less busy relatively soon.


The other problem has been trying to break this tutorial up into manageable chunks. I may have to switch to making it into an annotated example project instead of a tutorial (which might be better overall, and would let me make more content). Feel free to leave comments if you have any feelings about this (and I know some people have asked for that sort of change in the past).

Wednesday, December 16, 2015

OpenTK Tutorial 8 Part 2: Adding Textures and Specular Lighting

In the first part of this tutorial, we added normals. In this tutorial, we'll use them to do something interesting, adding specular lighting and diffuse maps.


Sunday, August 9, 2015

OpenTK Tutorial 8 Part 1: Normals, Materials, and Loading More From Files

In the previous tutorial, we loaded a simple object in from a file. Right now, it's hard to see the detail in the models because they're all one color (or have a texture applied wrong). By the end of this tutorial (that is, after the second part), we'll have diffuse lighting with specular highlights on our models, making them look much nicer.

This part will cover loading texture coordinates and normals from a file, calculating normals for geometry that doesn't come with them (such as shapes we're generating through code) and loading basic materials from a file.

(UPDATED 2015-11-24 to fix some issues with loading normals from a file)

(UPDATED 2015-12-16 to make the MTL file have materials that look nicer under lighting)

(UPDATED 2018-11-06 to make compatible with input handling changes in Tutorial 5)

Tuesday, April 14, 2015

OpenTK Tutorial 7: Simple Objects from OBJ files

This tutorial is going to be rather short. What we'll do is add a new class that can open very simple OBJ files and add some sample models to the project.


Wednesday, March 25, 2015

Inside the Sprite Example

Last time I posted a new example that uses OpenTK for a 2D view with sprites. Let's go into a bit more detail about how it works:

Tuesday, March 10, 2015

OpenTK Sprites Example

A new example is available on the GitHub repository:

https://github.com/neokabuto/OpenTKTutorialContent/tree/master/TKSprites




This example features 2D drawing of textures, with motion and alpha blending. 30,000 sprites are added by default, but you can add more by hitting the + key. Most of the sprites are off-screen (and not drawn to help keep things running smoothly), but you can move the view with the arrow keys (and speed up with the shift key) to pan around the world. Clicking on one of the sprites will change its texture! 

UPDATE 3-11-15: New feature: multiple shaders! Hit V to change which shader is used, or hit M to toggle a mode where the shader is chosen based on the texture.

Sunday, July 13, 2014

OpenTK Tutorial 6 Part 3: Putting it all together

Now that we have TexturedCube, and a way to load shaders and textures, we can finally get to the good part, drawing some textured objects!

In this tutorial, we'll be wrapping up the texturing content. At the end, we'll have two cubes being rendered with different textures on them.

Wednesday, April 23, 2014

OpenTK Tutorial 6 Part 2: Loading Textures and the TexturedCube Class

Now that we have our shaders loaded in a new, more object-oriented way, we're a third of the way to having textured objects in our program!

In this tutorial, we'll add a function to send textures to the graphics card and write a new class to give us a cube with texture coordinates. Unfortunately, we'll need to wait for part 3 to put these to use, but I'll try to hurry it along (summer is almost here)!

Tuesday, March 11, 2014

OpenTK Tutorial 6 Part 1: Loading Shaders with a Class

This tutorial will cover basic texturing. To add a texture, we will first need to have a shader that handles it. Right now, we're using one shader, with no way to easily switch to another without requiring everything to use that shader. In a real game or program, we would probably want to be able to use multiple shaders (for example, UI elements probably don't need lighting applied to them, but game objects probably do), so we're going to handle this with a class that allows us to easily add more shaders if we need them, and switch between them at will.

This tutorial is split in parts, based on how long it is. Each step is rather substantial (and this groundwork will make things easier down the line), so I hope everyone understands why it needed to be split up like this.

Friday, January 10, 2014

OpenTK Tutorial 5: A Basic Camera

Now that we have many objects displayed, let's make a way to see them properly.

In this tutorial, we will be creating a simple camera with WASD controls and mouselook.

UPDATED 11-6-2018: New and improved input handling!


Friday, November 15, 2013

OpenTK Tutorial 4 Addendum: The ColorCube class

Here's a little class that can show drawing multiple objects better. It's a cube with a solid color (code after the break).



Friday, September 27, 2013

Chain Jam Afterthoughts

The Copenhagen Game Collective just started a new style of game jam called the Chain Jam. The gimmick of the jam is that everyone makes a very small game for four players, and after a minute the players are funneled into another game, with the scoring staying between games. It's a fun idea, and easy enough to make a game for.

I made a game for it, called Four v. Horde. It's basically Left 4 Dead, but simpler, top-down and made by me in most of a day (instead of a semi-competitive FPS made by Valve over a year). Players try to kill the most zombies without being killed themselves.


While making it, I realized a few things about the Chain Jam concept:

Monday, July 22, 2013

OpenTK Tutorial 3 - Enter the Third Dimension

Now that we've draw one triangle the right way, let's add some real depth to our image. Here we'll be drawing a cube and rotating it so we can see our work from a different angle.

Sunday, June 9, 2013

Unnamed New Game - Gravity Test

This is just a little thing I was working on right now. Eventually this will be part of a real game. Eventually.

It's pretty obviously incomplete (there's no background, or loss condition, or menus, and it doesn't keep spawning things as you move away), but it's almost a start.
You can move the "player" (the one at the center of the screen) with either WASD or the arrow keys, add new bodies to the simulation with the numpad's plus key and reset it with the 'r' key.

Friday, March 8, 2013

OpenTK Tutorial 2 - Drawing a Triangle... the Right Way!

The previous tutorial showed us how we can draw a triangle to the screen. However, it came with a disclaimer. Even though it works, it's not the "correct" way to do things anymore. The way we sent our geometry to the GPU was what's known as "immediate mode", which isn't the newest way to do things, even if it is so very nice and simple.

In this tutorial, we'll be going for the same end goal, but we'll be doing things in a way that is more complex, but at the same time more efficient, faster, and more expandable.