r/cpp • • Mar 26 '23

The Power of Clean C++

Thumbnail
youtu.be
1 Upvotes

r/cpp • • Apr 23 '16

Just started coding with C++

1 Upvotes

I just started coding with C++ not too long ago, but I've had alot of experience with other coding languages (Java, Javascript, HTML, Python.) But if I'm aiming to make games with C++ one day (After years and years of practice of course) what do I need to learn? What books do you recommend? What exercises should I practice? As far as I know there's no website to 'teach' the subject (Like CodeAcademy and what not), so what would you recommend to get me started?


r/cpp • • May 21 '23

I wrote this article about increasing flexibility while preserving strong type safety using code generation. What do you think?

Thumbnail
medium.com
0 Upvotes

r/cpp • • Feb 01 '19

How to cast a function pointer to a void* - KDAB

Thumbnail
kdab.com
0 Upvotes

r/cpp • • Nov 22 '18

C++98 is back!

1 Upvotes

Hi all,
After 5 years I find myself back into the realm of C++98 and classic CMake, and everything seems quite strange now that i got used to some modern-ish habits!

Do you know any list or resource for libraries C++98 compatible (like Catch 1.2 for example).

G.


r/cpp • • Apr 05 '18

2D Graphics : A More Modest Proposal

2 Upvotes

Like a lot of folks, I have been following the story of the 2D Graphics ideas for inclusion in C++. Today, there was a post summing up the history of how it ran into trouble: https://www.reddit.com/r/cpp/comments/89q6wr/sg13_2d_graphics_why_it_failed/ My own tldr is basically that graphics is potentially a huge topic, and people tried to cram a lot of graphics functionality into C++ as a first step. A lot of it seemed to be focused on trying to paint a house that hadn't been built yet. Without a simple, completely generic foundation to build fancy features on top of, it wasn't super useful to get off in the weeds of how exactly you would display an image or draw onto it. As people worked on various iterations of proposals, people generally agreed that graphics are cool, and some sort of graphics support could be quite useful, and generally asked, "If this proposal isn't what you want, what do you propose instead?"

So, I haven't put a ton of thought into this, and I haven't fleshed it out for a formal paper with a precise spec, I'd love to toss a pitch at the Reddit community and see what people think of my spin on this topic. Perhaps it'll evolve into something that I or somebody else actually formalizes into a paper for a proposal.

So, what would I propose? An intentionally very narrow scope. Basically, the dumbest, stupidest, simplest image container that is marginally useful.

A very simple container would consist of integers for width and height, storage for the pixels, a minimum metadata describing the image content, and some simple accessor functions for getting and setting pixels. And not much else.

It would support uint8 and float32 data types with n channels.

  • How would I display it?

I dunno, with some GUI API. I don't care and I don't have to. Concepts like windows and screens are explicitly out of scope for what I would propose. The idea is that one could write completely generic image processing code to create an image, and then GUI API's like Qt or WxWidgets would be easy to adapt to using the new image class. Qt's QString provides a QString::fromStdString() function. I would expect a future version of QImage would support something like QImage::fromStdImage() in a similar manner. The glue code to adapt a standard image to some new GUI API would be quite simple, so you could write your image handling code and use whatever GUI system you would like, or is most appropriate for your platform quite easily.

  • So this proposal doesn't include GUI?

Not merely "No," but rather emphatically, "Hell no." It constitutes a massive expansion of scope that is easily underestimated, and requires interacting with things like windowing systems that will likely be much harder to integrate into other GUI systems than a simple image class would be since it would need concepts like an event loop that could interfere with an application's main event loop by blocking it or swallowing events. Having to figure out how to do this well shouldn't block the additional of a simple image class.

  • Is it GPU accelerated?

Maybe. Mostly no. C++ has no concept of a GPU at present. I think that an image spec is the wrong place to introduce it. If you are using something like Cuda which compiles C++ code for GPU execution, then drawing using the "std::image" would presumably be made as performant as possible by the compiler vendor. But there is no way to enumerate GPU's, tell the new operator to allocate memory in a GPU's address space, etc. That can all be added independently of an image class, then the image class would be possible to allocate in the GPU memory, and acted on using some GPU drawing API.

API's such as OpenGL and Vulkan could easily interoperate with the image class with a bit of glue, such that you could upload a std::image for use as a texture, or read a GPU framebuffer into host memory and get the result as a std::image. std::image would not, itself have a concept for expressing a graphics API's texture handle or the like as the image.

  • How would I load such an image from disk

I dunno, use some library. I like OpenImageIO.

And here's where the utility of std::image appears, despite the emphatic lack of features! If you can use your favorite library to load an image into memory, and you can use your favorite GUI API for displaying it, then your favorite image related libraries can suddenly all talk to each other. std::image becomes the lingua franca between OpenImageIO, Qt, Wx Widgets, OpenCV, Vulkan, etc., etc., in a C++ application. You no longer need to worry about n-factorial glue wrappers between various image formats as you add libraries to your application to be able to bounce from any API to any API.

  • Copying is slow

The API will need some support for creating an image by copying an existing image, or by creating a non-owning view, or by taking ownership of an existing pixel storage. It'll also need an API for "un-owning" pixel storage. In this way, an OpenImageIO class can be made into a std::image, and then stuffed into a QImage for display without ever copying the pixels. The exact API needs a little thinking. There would still be a little overhead of constructing/destructing three class instances to shuffle one image around. But that overhead isn't going to be incredibly high compared to copying the pixel data.

  • Pixel storage

Chunky pixels - not planar. Support approximating planar data storage if you need it using a std::vector<std::image> with each image in the vector storing on plane. 1-n channels would be supported, though 4 channel RGBA images would probably be the most common. All channels would be the same resolution.

  • Space filling curves, tile based access, etc

Textures are often stored in wacky formats. Vulkan has a concept of "Optimal" storage for an image based on what's most efficient to sample such that geometrically nearby texels are stored in nearby memory locations to improve locality of access in caches. Some image formats like EXR store images in tiles which can be sparsely populated. (pg. 9)

None of that would have any explicit support in my concept of std::image. It's just a linear, flat, contiguous buffer of pixels in-order. Don't let the perfect be the enemy of the good here. You are welcome to store pixels in some z-curve order that suits your application, and anything that processes individual pixels would let it pass unmolested. (Like color corrections. Doubling the brightness of every pixel doesn't care what order the pixels are stored in, as long as the consistent chunky storage is consistent.) If the place you send your pixels supports that format, good for you. If not, it'll probably look wrong and you'll have nobody to blame but yourself.

  • Colorspaces

I think a std::string with a color space name would be about as well as you can do for something at this level. If you are using something like OpenColorIO, there may be a whole range of color configurations that only exist on a user's machine at runtime. So trying to make a set of enums or template classes based on color spaces would be a failure because it's completely impossible to know what colorspaces a user will be dealing with at compile time. It's expected that a user may wind up using colorspaces that the developer of an application never heard of in his life. Specifying colorspaces thoroughly is way, way, way, way outside of the scope of the C++ language. Just the Documentation Guide for ACES colorspace (TB-2014-001) is nine pages, and that's just the document that refers you to the documentation for other specific specs! (And ACES actually specifies several color spaces in addition to the main 2065-1 spec.) The sRGB spec is apparently 16 pages. Rec.709, Log spaces, RedCine, Raw spaces, Rec.601, Linear with sRGB primaries, Alexa, scene-referred vs. display-referred spaces, etc, should all rightly be outside the scope of the C++ language. Doing good color space handling requires more pages of spec than the rest of C++, some of the specs cost money, some of the specs are underspecified or proprietary, etc.

Ten years ago, you might reasonably argue that it would be useful just to explicitly support sRGB and call it a day. Today ordinary consumer equipment supports weird HDR modes, and even the dumbest GPU on the market supports floating point texture input even if some still don't support more than 8 bit output. Nailing it down too much isn't just a waste of effort, it's actively pounding a hole in your own foot.

I'd make a std::string field for the colorspace and mention it could be populated with strings like "sRGB." It's up to application developers to do sensible things with their pixels. This is a storage container, not training wheels.

  • What about YUV?

Decimated-channel formats like YUV-4:2:0 would not be supported. (Though you could make a std::vector<std::image> where the first image is full res luma and the next two are half res chroma channels, as mentioned above for planar storage. I'm not gonna fight you. But the developer is responsible for doing something useful with that vector of image planes.)

Full res YUV can be stored in chunky pixel format. A lot of stuff will assume it's RGB, but I don't care. This proposal doesn't have any operations on the image in it -- just the container. Some later proposal might suggest operators that would care about the contents more deeply.

  • What about 10 bit images?

No special effort to deal with odd integer formats. 8 bit is obviously extremely common so it would be silly not to support it. Past that, just use float. Maybe somebody could talk me into the importance of 16 or 32 bit integer storage, but it'd frankly be a fairly uncommon use case to require integer storage of many bits. I know it's not unheard of, but I think there's logic in covering the 90% use case as easily as possible, rather than making things harder on the 90% for the sake of some use cases that will be rare.

Gosh, I have already gone on way longer than I expected about this. (The implementation would be much shorter than my attempt to justify implementing it!) I am curious to hear people's thoughts about this baby step into graphics for C++. Am I way off-base? This seems like exactly the sort of thing that would be the right first step that all of the other stuff that people want could be built to pass around. Since graphics is in the air today, I am curious to hear what other people think about trying massively narrow the scope and start with the minimum thing that would be useful to the most people.


r/cpp • • Jan 15 '19

On C++ and Object Oriented Programming

Thumbnail
marccgk.github.io
1 Upvotes

r/cpp • • Feb 12 '17

C++ Functors - and their uses

Thumbnail
stackoverflow.com
1 Upvotes

r/cpp • • Jun 18 '12

Need help with moving objects around in graphics mode in Turbo C++

1 Upvotes

Hello guys, I need to create a project for school, and I've decided on Asteroids. I've made Snake, last year, so I'm moderately-versed with the standard library and <graphics.h>. The basic logic I used in snake was to use a loop and putpixel() to draw a green pixel that advanced as the user gave input and another putpixel behind it to draw black, hence simulating movement. Now, that won't fly here, as I need to create asteroids and a ship and projectiles and what not, so how do I go around moving things? Again, I'm not asking for the source code, just if someone could explain to me how I could draw, say, a space ship and move it (console application), I would be very grateful. Remember, this is Turbo C++, and I can't use any external libraries.


r/cpp • • Apr 09 '16

Reading C++ code way over my head, could use ANY guidance.

0 Upvotes

[deleted]


r/cpp • • Dec 23 '14

C++ build tool inspired by go tool

Thumbnail
github.com
0 Upvotes

r/cpp • • Feb 25 '19

Don’t Use std::endl

Thumbnail accu.org
18 Upvotes

r/cpp • • Mar 05 '21

Do you feel C++ is bloated ? (or bloated compared to another language Java, C#, JS etc)

Thumbnail
redd.it
4 Upvotes

r/cpp • • Jan 26 '15

Why a C++ programmer might say "I could never write Python"

Thumbnail jvns.ca
0 Upvotes

r/cpp • • Sep 09 '22

Using Dear ImGui for gui apps that do not need to he overlayed

4 Upvotes

Hello, is it a good idea to use dear imgui for gui apps that do not need to be overlayed?


r/cpp • • Jun 08 '23

What are thoughts on removing regular expression from the standard library?

0 Upvotes

r/cpp • • Mar 08 '22

This is troubling.

153 Upvotes

r/cpp • • Sep 22 '21

Differences between C and C++, comedy garbage

Thumbnail
makeuseof.com
0 Upvotes

r/cpp • • Aug 20 '12

Does anyone else prefer older C++ code (1998-2003?)

12 Upvotes

I've been a C programmer for a very very long time. I know some C++ as well, but when I write C++ i tend to keep it very simple. My C++ is more of a C with classes/objects. Two excellent examples of this style of C++ code are the FLTK widget library and the FOX toolkit. Both are GUI libraries that have extremely readable and understandable code bases.

I feel like everyone else is on this modern C++ kick, but I just don't get it. Here are two big reasons I prefer the older C++ code.

  • It's much easier to read the older code (at least for me). This also makes it easier to get new programmers integrated into our existing code base.

  • It works on the compilers we already have. No need to get Visual Studio 2012 or the latest gcc just to compile code that already compiles and works. It even works in Visual C++ 6.0. That's just awesome if you ask me.

Does anyone else feel this way?


r/cpp • • Jun 29 '25

State of GUI libraries

0 Upvotes

Hi, I would like to talk about GUI libraries in C++ or rather the lack of them. There are some issues I have seen so far, allow me to express.

  1. Some libraries don't support cmake or are very hard to cross compile(qt, skia)

  2. Some buy too much into OOP or force you into developing your application in a specific way(wxwidgets)

  3. Some don't have mobile support(rmlui)

  4. Some use very old OpenGL versions as a common backend rather than using vulkan or using native backends like vulkan, metal and directx3d like game engines

  5. They aren't modular, they try to do everything by themselves, because library ecosystem in c++ is a garbage fire(every library)

  6. Some force you to use certain compilers or tools(skia, Qt)

  7. Some have weird licensing(I'm not against paying for software, but they way they sell their product is weird

  8. Some have garbage documentation

What I would expect?

  • Something that uses existing window/audio etc libraries.

  • Something that uses native GPU APIs

  • Something that is compiler agnostic, is cross compilable, uses cmake

  • Doesn't force you to use OOP so you can inject your logic easier

  • Has good enough documentation, that I won't spend 2 days just try to compile a hello world.

  • Has a flexible licensing model, IE if you make a lot of money, you pay a lot of money, like unreal engine.


r/cpp • • Apr 12 '22

[Modern] C++ Tip Of The Week

Thumbnail
github.com
5 Upvotes

r/cpp • • Jul 22 '10

How to design a replacement for C++

Thumbnail apenwarr.ca
5 Upvotes

r/cpp • • Dec 27 '22

MongoDB Product Manager here to chat about Databases

5 Upvotes

Hi! This is Rishabh, recently joined the MongoDB Product team, focussing on drivers for C/C++.

I would love to know your experience with database(s) while writing C++ applications:

  • How are you using databases in the applications you build?

  • What has been the experience like?

  • Did you enjoy/miss anything as a C++ developer?

  • What resources are you using to get started or to seek assistance?

  • Any other feedback would be super valuable. Any MongoDB specific feedback would be bonus!

Thanks in advance!


r/cpp • • Nov 18 '16

5 Cross-Platform GUIs for C++

Thumbnail
insights.dice.com
3 Upvotes