0
$\begingroup$

First of all I am not sure if this is the correct place to ask my question. If it is not please be so kind to point me in a direction where my question is relevant.

A while ago I came across this cross platform graphics library called Veldrid.
Resulting in me getting the idea to write my own processing clone but then for C#. Only problem with this plan is that I have absolutely no knowledge about graphics programming. So I started researching the matter with little luck... since what i found was either too generic or way to academic.

What I really want to know is; is it even possible to write a 2d renderer with a gpu powered graphics library (eg opengl, metal, vulkan etc). And if so how do you write the renderer?

My initial way of going about it was the following: create a bunch of shaders to render things like rectangles, ellipses, triangles, lines etc. and linking them with a uniformbuffers to send shader properties on how to draw the ellipse colour for example.

But this seems to become very dumb when having to render lines, since in this case i would make a quad have a shader draw a line in the quad and have the leftover pixels transparent. Which seems very inefficient.

Any advice would be super helpful! But please keep it noob friendly since i am no where near an amateur on the subject :)

If any clarification or additional information is needed please let me know!

$\endgroup$
1
  • $\begingroup$ Yes it is. (A lot of applications are allready doing this) What you do is you draw triangles and shade them with a shader. But trick is that you draw half segments on minimum boundingboxes. Or you just draw a bunch of linear segments with line primitives. Or you could just you know draw a rectange and shade ot all in one go. Anyway theres quite much learning you need to do. $\endgroup$
    – joojaa
    Jan 7, 2022 at 8:06

1 Answer 1

1
$\begingroup$

Writing a 2D render system is a perfectly reasonable thing to do using any of the Graphics API's that you listed.

Triangles are the basic medium of all the popular graphics API's so learning to work with, and manipulate triangles whether it is in 2D or 3D is one of the big hurdles to getting a render system up and running.

OpenGL tends to be the most popular and is (usually) considered to be the easiest API to learn. There are many tutorials on OpenGL as well, most of those tutorials like learnopengl.com are focused on 3D, but working through those examples will familiarize you with the interface also a 2D rendering system will use the same interfaces just in a slightly different way.

You will have to learn some linear math for things like rotations and translation, but the good news is almost all decent resources on the subject start out by describing 2D linear math. The bad news is that there is really no way around the academic side of the math. The really bad news is that a 2D homogenous coordinate system is the best way manage objects. A homogenous coordinate system allows you to put objects in there own private coordinate systems, do "work" on objects inside that coordinate system, and then easily move objects into a different, usually shared, coordinate system. It sounds complicated but once you get the main ideas it is actually very easy. Also there are some outstanding entry level books on the subject that cover 2D rendering really well.

The next major component of the rendering system is the actual code that it gets written in. C++ tends to be the most popular mostly because it is a fairly expressive language that can be optimized very well. However learning the entire C++ language can be very daunting. Luckily you can pick and chose some areas of the language to get started then expand your knowledge base as you become familiar with the language. These days scripting languages offer decent efficiency and tend to be easier to learn. A scripting language could be a good choice since it would allow more development focus to be put on learning the graphics side. Unfortunately scripting languages have limits. They don't expose the entire graphics API, they don't allow very low level access to the hardware, and they have performance limitations. But much of that can be worked around. (except the performance which is what eventually drives many programmers to languages like C++)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.