Salomonsson.se
Sep 24 2019

Starting out with C++ and SDL

I’ve spent some time trying to port my text engine to linux and mac, with the following results:

  • On Linux (also valid on Mac) I cannot detect keyUp. “Fixed” it by gimping the game a bit on those platforms…
  • On OSX I cannot set colors correctly! The exact same sourcecode that works on Linux turns into dark blue text on semi dark blue background. Unreadalbe.

So I have abandoned that path for now. Instead started looking into the SDL library instead… and it is really smooth to work with! (at least on Linux). I have currently managed to get it to work on both Linux and Windows!

I can even work with this code on my old, very beloved, Asus EEE 1005PE netbook. A ten year old 10.1" computer that freezes if it tries to open any random webpage (Gmail? Just forget about even trying), however it has a whooping 250gb harddrive, a keyboard like a dream and a battery that lasts for an eternity. Writing C++ code in VIM (in a terminal window) works like a charm… like in the 70’s ;-) Compilation is around 1-2 seconds, which is not only acceptable, but also faster than Unity compiles on my powerhorse workstation.

This looks very promising for the upcoming Ludum Dare competition!

Apr 19 2018

Cpp text console application, part 3

Now writing to bufferes and writing those to the output. Writer class that prints text character by character and interprets simple commands (right now only newlines and changes in speed and pauses). Two days left to Ludum Dare.

Tutorial that describes pretty much exactly what I’m playing around with

http://cecilsunkure.blogspot.se/2011/11/windows-console-game-writing-to-console.html

Good to keep as reference!

https://github.com/Tommislav/cppTextEngine/commit/1110c6c53b7abb51c5c5a34364d7f450046d8c35

Mar 15 2018

Cpp text console application, part 2

More fun with your terminal:

  • Colors
  • Write character at position

So far I’m surprised by the speed (the delay you see is actually me pausing the thread)! The last time I tried stuff like this directly in the terminal it flickered like hell. But that time I was using conio.h, this time I write stuff myself using only windows.h.

I’m not using buffers yet, only moving cursor and writing to that position. Guess writing to buffers will make it even faster. But thats for another day…

Feb 11 2018

Cpp text console application

Ok, for the first time in a long while I got two hours that I could spend on programming! Need to refresh my c++ knowledge quite a bit (the metro siberia part below uses OpenFrameworks to do all the heavy work for me). But in these two hours I still managed to:

  1. Create a makefile (my very first one)
  2. Code a small console application in VIM (and compile it using :make)
  3. Have the program print out text letter-by-letter
  4. Read the content of the text from an external text file
  5. Store config flags, such as speed or pause in the text document

Not very exciting, and now the time is up. Time to hit the bed. Felt good to do some programming anyways.

Sep 14 2017

Metro Siberia - part 2

Matrices!

Small progress. Started porting over my matrix implementations from haxe. At the moment it actually looks more like C-code than C++.

Aug 24 2017

Metro Siberia - part 1

intersecting triangles

Started a re-make of my old game Metro Siberia in C++. This is the big plan:

  • Custom rendering methods in it’s own header file
  • Game code is platform independent
  • To start with, only draw lines and simple fills
  • Currently using OpenFrameworks as “backend”, because it is almost zero hassle to get working
  • Plan is to change from OpenFrameworks later on… but we’ll see. At least the structure will allow it.

Currently nothing more than a window that renders the picture above.

Sep 21 2015

Playing with shaders - Part 3

My recent days of night dev has been a bit fragmented due to the fact that I have two newborn kids that require a lot of attention. But whenever I get a spare moment I try to do a little bit of programming, so todays post is actually the result of several short days of work.

First of all I needed to read up on plasma effects again. Haven’t done that in several years, and it turned out I did not fully remember how it was done. But I did find the excellent tutorial I used several years ago, I highly recommend reading it!!! It is ugly, but very interesting read: http://lodev.org/cgtutor/

After that I started playing with shaderToy, trying to get a plasma shader running.

And lastly, I implemented that shader into my c++ sandbox project. Something seems to be a bit off though, it is way to bright. I think it is because the range of each sine/cos-effect (that is merged together to form the plasma) has an incorrect range (not 0-1), or perhaps the area is too zoomed in – but it’s too late to start bug-hunting now so this will have to do for now.

Next up: colors and bitmaps!

Sep 10 2015

Playing with shaders - Part 2

Spent several hours rewriting my setup code to play with shaders. This is a tutorial that explains it very nice and cleanly: https://open.gl/introduction

I also found a library for loading png files from disc, that don’t require you to invoke make-scripts and all that madness. Just add one .h and one .cpp-file to your project and you’re done! The name is LodePNG. However, did not come far enough to read textures into my shader.

However I managed to get uniforms working, so I could pass the current time to my shader and animate it. I guess that’s something. That’s all for tonight.

Sep 08 2015

Playing with shaders - Part 1

Since I became a father of two twins, two months ago, I haven’t been able to do much coding at all. Any opportunity I get I have to make sure I do something really small since my work time gets very fragmented.

So I started a c++ project, open a window with an openGL context, and started playing with some really basic shader code. As I said, I didn’t get very far before I had to abort. But it’s something.

Just wanted to save the links to some pages that helped me setting up GLFW on windows in Visual Studio 1013. http://www.41post.com/5178/programming/opengl-configuring-glfw-and-glew-in-visual-cplusplus-express

http://www.codeincodeblock.com/2013/05/introduction-to-modern-opengl-3x-with.html

https://github.com/smokindinesh/Modern-OpenGL-Series

#version 420 core

out vec4 color;
void main() {
float x = mod(gl_FragCoord.x, 100.0) / 100.0;
float y = mod(gl_FragCoord.y, 100.0) / 100.0;
color = vec4(x,y,1.0,1.0); }
Mar 10 2015

C++ and openGL... creating a window

Took a short break from the Unity project to go into C++land. Decided I wanted to play around a little with some C++ and openGL.

I wanted to develop on my Linux partition (why make it easy for yourself?) but make the code cross platform so I’ll still be able to run it on my windows machine. I decided I wanted to use glfw for all the window, input and timer hassle. It seems light weight, and it is used in this tutorial by my colleague at Isotop (he named the blog series “I’m not a smart man” for some reason. Trust me that it is very far from being true!)

So, did it go smooth? Not at all. I’ve spent a bit over three days trying to figure out how in *#¤% you manage to tell Code::Blocks how to find and link the libraries I want to use. I’ve covered it in a blog post, mostly for my own convenience. Probably full of incorrectness.

Well, now I have a spinning triangle in a window. Time to make something more interesting!

Mar 10 2015

C++ and openGL - Part 2

Continued with the C++ project. Noticed that the sample code for my triangle was in the older glBegin…glEnd format and changed it to the new opengl 3 standard with shaders, only to get a totally black window. Turned out you need to add the following code to enable opengl 3 and core profile:

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

Which gave me a triangle once more.

The rest of the evening was spent re-reading about matrix operations, and the Model-View-Projection matrices. It was a long time since I last played around with this. You quickly forget if you do not keep working with it.

Feb 02 2015

handmade tommy part 1

Since the Christmas Holidays I’ve started watching the fairly new stream Handmade Hero, where we get to follow Casey Muratori, as he builds a game in C, from scratch, without any libraries, and streaming and explaining every single line of code that he writes.

I’ve been struggling with C++ for a while now, but it’s very difficult to find answers when you get into a situation where you need help with a specific problem. There are endless ways of solving the same problem in C and C++, and very often you will get contradictionary or incomplete solutions. And a lot of times people just answering “You shouldn’t do it like that” and then nothing more.

So I enjoy this video stream very much. Casey explains every single line of code he writes. And also sometimes explain other ways to solve a task, and why he prefers the one or the other. He also tackles some very advanced topics, like how to structure your code to get a good foundation for platform independance. And he does it very elegantly.

The stuff he teaches is not something you wouldn’t easily find in any text book, and corresponds to years experience, so I highly recommend watching.

At this point I’ve watched Episode 13, and coded up to episode 5. I Haven’t anything more interesting to show right now than a simple window, with a simple animated buffer (rendered in software) in Windows. All I have to show for it right now is a simple Screenshot.