Showing posts with label SDL2. Show all posts
Showing posts with label SDL2. Show all posts

Wednesday, 6 October 2021

Home Engine - Loading PNG Textures into DirectX11 with SDL2

ANYONE Interested in my sharing the code to do this?  Leave a comment, 10 comments and I'll blog it.


I'm using SDL2 as the background framework for providing cross platform input and window handling, but I'm writing my own renderers for various platforms (DirectX11, 12, OpenGL and Vulkan).

All of them support coloured shape and line renderering to one extent or another, so I decided to take the leap into texture mapping.

First of all I put in all the framework to represent textures in my engine in a cross platform manner, and for ease I decided to use SDL2_Image to load my pixel data.  And I started with a simple PNG file I created in MSPaint....

Immediately I ran into issues, PNG is RGBA, the png I created had a transparent background as far as I knew it should all work.  I swapped to RAW pixels and I was getting 4 bytes per pixel, it was only after a bunch of reading and then stepping into the SDL_Surface format did I realise the data might be whatever format but the surface was clearly 3 bytes per pixel.  And funky things were happening.

My assumption that MSPaint was outputting 4 bytes per pixel was just wrong, instead it's 3 bytes, RGB.  And there's no matching DXGI_FORMAT for just RGB - least none I could spot.

A quick reexport in GIMP setting the explicit pixel format to 8bpc RGBA, which then of course just worked....



Therefore, it's official, using an SDL2_Image load of a PNG as your DirectX11 texture is perfectly possible.

And for me, this reduces the need to include yet another library (other than SDL) to handle image loading.

----

Not even sure how, but this older video got attached to this post, which is about "SuperSampling".... but really just changing the renderer to window resolutions...


Tuesday, 4 August 2020

Raw Graphics Engine : C++ Project

It has been a whilst since I had a personal improvement project grace these pages, so here's one I started over the weekend.... A graphics engine.

Sure this is something I play about with all day in the office, we're writing games!  That's literally my job, but I've been a system engineer for such a very long time, and I've seen all these sparkly things coming from folks working on game play and wanted some sparklies of my own.

I therefore began two projects, both are graphics engines, but they're very different from one another... one is in Vulkan, which is not what we're talking about here, no we're talking about the other one... And this is a graphics engine I've written myself.

It's gone through three phases since Saturday, Sunday and then just tonight.  The first phase was setting up the basic rendering, getting a triangle on the screen and making it flat (orthographic) projection.


The engine is written in C++, uses SDL2 for the window and renderer, but the engine itself does all the geometry transforms through linear matrix mathematics that I hand crafted, and it reaches into the third dimension in orthographic mode.



The shapes can be rotated, scaled, translated, the usual.  But before I drove myself mad with writing shapes by hand on graph paper, I wrote a very simple importer for the very simple Milkshape 3D model editor, and started with a sphere:



Milkshape has appeared on these pages before and is really the only modelling package I'm familiar with, I really do need to learn Blender don't I?

So with models loading I got a little adventurous:




This mesh really stresses my single core linear mathematics, so I started to switch it out in favour of GLM tonight:

// Model
glm::mat4 model(1.0f);
model = glm::translate(model, trans);
model = glm::rotate(model, glm::radians(angleZ), { 0, 0, 1 });
model = glm::rotate(model, glm::radians(angleY), { 0, 1, 0 });
model = glm::rotate(model, glm::radians(angleX), { 1, 0, 0 });
model = glm::scale(model, glm::vec3(scale.x, scale.y, scale.z));

So, that's been my three days.. I'm interested where and what I will do with this engine.


However, Vulkan, that's the other thing I'm learning.

Wednesday, 25 December 2019

C++ Programming : SDL2 Graphics Rendering Loop

Today, it's a bit of a programming ramble, I'm literally throwing this code together, from memory and the docs... What does it do?

Well, I set up an SDL2 based graphics project.  Added font loading and set up the compilation environment and get something updating on screen, at the end there's then a second short video debugging a flickering... or if not properly fixing it, I at least start to pull the thread as to what is going wrong.

You can find the final code here: https://github.com/Xelous/Frog


And the short follow up: