107

2D / 1D - mapping is pretty simple. Given x and y, and 2D array sizes width (for x-direction) and height (for y-direction), you can calculate the according index i in 1D space (zero-based) by i = x + width*y; and the reverse operation is x = i % width; // % is the "modulo operator", the remainder of i / width; y = i / width; // where "/" is an ...


88

I guess people often claim that C is faster than C++ because it's easier to reason about performance in C. C++ is not inherently slower or faster, but certain C++ code might obscure hidden performance penalties. For example, there can be copies and implicit conversions which are not immediately visible when looking at some piece of C++ code. Let's take the ...


34

update: See bottom of reply This answer comes a bit too late, but I hope to shine light to others (particularly now that C++ standard committee wants to incorporate Cairo into std): The reason nobody really cares about "accelerated vector graphics" is because of how GPUs work. GPUs work using massive parallelization and SIMD capabilities to colour each ...


31

Code written in C++ can be faster than in C, for certain types of tasks. If you prefer C++, use C++. Any performance issues are going to be insignificant compared to algorithmic decisions of your software.


25

I don't think it is really true that nobody really cares about "accelerated vector graphics" as written in this answer. Nvidia seems to care a fair bit. Besides Kilgard who is the lead technical guy on NV_path_rendering (henceforth NVpr to save my fingers), the Khronos president, Neil Trevett, who is also a VP at Nvidia, has promoted NVpr as much as he ...


23

One of the design principles of C++ is that you don't pay for features you don't use. So, if you write code in C++ and avoid features that don't exist in C, then the resulting compiled code should be equivalent in performance (though you would have to measure this). There is negligible cost to using classes, for example, compared to structs and a bunch of ...


15

In my company, there are a few people specialized in this job. They are designers. And they know HTML. They can be a bridge between the designers and the front-end engineers; which they usually are. This way, we just have to integrate their HTML. This is a hard job. There's a reason sites like "PSD to HTML in 24h" work well. The solution in our company is ...


14

One reason that higher level languages are sometimes slower is that they can hide behind the scenes a lot more memory management than lower level languages. Any language (or library, API, etc) that abstracts away low level detail can potentially be hiding costly operations. For example, in some languages simply trimming trailing whitespace from a string ...


13

OpenGL only has functions to work with a graphics context, nothing else. You need at least a platform integration library to get such a context. But in reality you of course need more functionality, such as input handling. GLFW, GLUT and SDL2 are just different ways of getting such additional functionality. SDL2 is nice because it also includes audio and ...


11

In the past, I have found that using a spreadsheet application such as Excel to generate test data has been very useful for testing mathematical code. Writing the same mathematical model twice using two different tools (a programming language and a spreadsheet) helps you spot any mistakes, and ensures that the test data you generate is independent from ...


10

There are a couple of things you could try: Try to find some example values that are "obviously correct" (in the sense that any future maintenance programmer can easily see that and why they are correct, and verify their correctness in their heads without using a calculator) Look up the paper your algorithm comes from and see whether they have examples ...


9

OpenGL is a library that provides services like 3D rendering but doesn't do anything like creating a window that you can render into. OpenGL doesn't know anything about windows, or mouse events, or keyboards, or fonts and so on. It only knows about rendering. Because you probably want to render things visible on the screen you can't "use OpenGL on its own" ...


8

I believe it is somewhat bound up with development of technology and applications. The case Text sent over serial communications, goes first character first, second character second, and so on. IMHO, it makes no sense to do otherwise because we can start reading as soon as the message starts, and we don't need any extra layout information. For western ...


8

In cases like these, where the unit test would essentially be duplicating the function, I've often wondered if I should be writing unit tests at all. What I've come to conclude is that sometimes yes, it is valuable. In most cases I wouldn't bother with such a test, but for any critical part of a system I would because, although the test itself doesn't seem ...


8

OpenGL didn't 'embrace' global state so much as it was one of few sensible solutions to a technical problem. It's expensive to communicate with a video card. Flipping bits in video memory is considerably more expensive than flipping bits in ordinary memory. As an example it's so significant that later versions of OpenGL got rid of immediate mode, because ...


8

You either pick a language that allows the syntax you want, or write it out longhand and accept that it "look[s] horrible". For vector arithmetic, there are at least 3 different operations that are reasonably denoted by * (or times or product), and you'd have to have a language that takes return types into account to disambiguate all of them. It's then not ...


7

My question is, how does a program tell a graphics card to process something instead of the CPU? The short answer is that every graphics card must come with a driver implementing a standard graphics API such as OpenGL or DirectX, so that the code running on the CPU can call standard functions from that API. When writing your code, this is largely ...


6

I'm not sure there is a "right way", but a reasonably effective way of cooperating with a designer is to first build an unstyled system that uses templates and allows for the easy interchange of all templates. Then, once you have a functional-but-unstyled (or minimally styled) interface, you hand the results over to the designer for styling. A decent ...


6

The thing you have to remember is that every float-to-int conversion and vice versa potentially loses information. On most implementations, int can store a larger integer number with full precision than float, while float's decimal values are chopped off when converting to an int and that float can store larger numbers than can fit into an int. Now for your ...


5

For what it's worth, I tend to write my libraries in C++11 for the enhanced feature set. I like being able to take advantage of things like shared pointers, exceptions, generic programming, and other C++ only features. I like C++11 because I've found that a good bit of it is supported on all of the platforms I care about. Visual Studio 2013 has a lot of the ...


5

OpenGL is a 3D graphics API. It provides APIs describe a 3D scene and render it to a framebuffer and ultimately display it on a screen. The primitives it has are vertex lists, triangle lists, normal vector lists, etc. n.b. 2D is a special case of 3D; IIRC OpenGL doesn't have explicit 2D support (i.e. sprites and bit blit) OpenCV is a computer vision (CV) ...


5

While I think the upsides you provided can be true, there is one particular upside for matrices that I think matters a lot: almost all transforms that one wants to do in graphics - scaling, rotation, translation, etc. - can be represented as matrix multiplication. It's nice to have a common format - an interface, if you will. Additionally, compositions of ...


5

There're several good reasons for representing transforms as matrices: Vectors are used a lot in 3D graphics; Matrices are efficient data structures to store multiple vectors; The modern graphics pipeline is shader-based and requires the client application to send data quickly (e.g. buffers); The client can use a single function call to send the transform ...


5

The Introduction from the Dolphin Progress Report: January 2015 answers your question at least partially: zfreeze is a notable feature of the GameCube/Wii GPU with no real equivalent on modern PC GPUs. It can "freeze" the depth value for pixels in a polygon to an arbitrary reference plane. The intended use for this was to combat z-fighting, that ended up ...


5

It's extremely popular, dominates on mobile devices, is in active development, and supported on all kinds of GPUs. Why? Well... what's your alternative? Ignoring Vulkan, if you want to write a cross-platform application for mobile devices, and you want to use hardware 3D, what exactly are you going to use except OpenGL ES? Nobody has ever claimed (at ...


5

I figured it out. Took me all day but got the alignment pretty decent for that. What I did was convert a font to SVG, manually copy-paste out the glyphs into JavaScript. Import each one individually into Illustrator, export with alignment in right place (and Illustrator export produces completely different SVG paths than what you provide somehow). Take the ...


4

A good tutorial for low-level graphics on Linux is available here. A good post on stack overflow for low-level input is available here. Regardless, you probably want to use framebuffer or drm/kms (framebuffer being the simpler of the two) for graphics and evdev for direct input on Linux.


4

The performance difference between C++ and C is not due to anything in the language, strictly speaking, but in what it tempts you to do. It's like a credit card vs. cash. It doesn't make you spend more, but you do anyway, unless you're very disciplined. Here's an example of a program written in C++, which was then aggressively performance tuned. You need to ...


4

You already have both alternatives, so what is stopping you from running 1000 times each one of them and checking the average times for each? Then, after that, it is just a matter of picking up the fastest one. Once you are done with your tests, update your question and let us know.


Only top voted, non community-wiki answers of a minimum length are eligible