how are graphic's API's created such as DirectX and OpenGL. And is using GDI which is the graphic portion of the winapi, a graphic API itself? or are you able to create your own with C++ for 2D rendering instead of using anyone elses. Or does writing an API involve assembly.

Dani AI

Generated

As asked and as and began to point out, the important distinction is between an API specification (what calls look like) and the code that implements those calls on each platform or GPU. OpenGL is chiefly a public specification implemented by graphics vendors; Direct3D is Microsoft’s API/runtime that talks to vendor drivers; GDI is a legacy, OS-level 2D raster API provided by Windows and not the same thing as a modern 3D driver model (OpenGL overview and Windows GDI docs).

Under the hood there are layers: a user-mode runtime/library exposing the API, a vendor-supplied driver that translates API calls into GPU command streams, and kernel/firmware pieces that manage device access. On Windows this is formalised by the display driver model (WDDM); on other platforms the mechanism differs. Vendor drivers do the heavy lifting (shader compilation, command encoding, memory management), so APIs mainly define the contract between app and driver ().

Writing your own 2D rendering API is entirely feasible in C++ without needing assembly. Typical practical approach:

  • design a surface/pixel-format abstraction and double-buffering,
  • implement basic rasterizers (lines, fills, blits) in efficient C/C++ (use SIMD intrinsics for hotspots),
  • add batching and clipping to reduce per-primitive overhead,
  • provide backends: pure software framebuffer, and optional GPU backends using OpenGL/Direct3D/EGL for acceleration.

Notes and cautions: implementing a full, robust cross-platform API or a vendor-quality driver is a large engineering effort and requires deep OS/hardware knowledge (drivers run at privileged levels and must follow platform rules). Assembly is rarely required except for tiny, highly-optimized inner loops; modern compilers and SIMD intrinsics cover most needs. For most projects, reusing a battle-tested library (Skia, Cairo, or a small GL/D3D backend) is faster and safer than reinventing the entire stack.

Recommended Answers

All 4 Replies

To my knowledge, both DirectX and OpenGL are written with C or C++. You could write an API like them yourself using C++. On Windows, you can use SetPixel() to set a pixel on a screen. I believe that's one of the most basic graphical functions you can use (in the Windows API). Then it's up to you to write bitmap loaders and the like.

so are directx and openGL just MASSIVELY modified versions of GDI with the winapi so that it can handle 3d rendering and all that good stuff.

I guess you could classify DirectX as that. OpenGL, on the other hand, is multi-platform, so it can't always be using the Windows API. I'm not sure how OpenGL handles being multi-platform. Perhaps the different versions of OpenGL for different platforms are coded slightly differently internally. I can't say for sure.

perhaps the drivers of graphics cards also used to know the right memory locations etc for directx and opengl...
at the end, GDI also has been made by man kind, so i think parts of some rlly low-level things are asm.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.