hedgehogrider
hedgehogrider

Reputation: 1198

Where can I learn how to interface with a graphics card using C++?

I'm learning c++ right now and I'd like to start interfacing with a graphics card and play with the basics of 3d graphics. I haven't found it in my book or in internet queries, and I actually have absolutely no idea where to start with this. Can c++ code run on a graphics card once it is compiled? I understand that I access GPU processing through OpenGL but I'm unclear whether this is just a library for accessing through c++ (and probably other languages) to pass functions to the GPU, or if it is specific to GLSL. So what is OpenGL, and how can I use it in conjunction with c++ in order to pass processing to the GPU? Are there other more direct or flexible ways to work with C++ and a graphics card?

Upvotes: 11

Views: 8325

Answers (6)

Kos
Kos

Reputation: 72241

Are you interested in using GPU for...

Graphics: You have two interfaces, OpenGL (multiplatform) and Direct3D (Windows), both supported by virtually all GPU drivers.

Calculations: The most common interface ATM is CUDA by NVidia (only for GeForce cards). There's also OpenCL (should be supported everywhere, but I'm not sure about current state on GeForces; all OK on ATI) and some proprietary solutions by AMD/ATI with which I'm not familiar with.

Pick whatever you fancy and start learning it, there's a lot of examples and tutorials for any of the above to be found online.

Upvotes: 0

Natansh
Natansh

Reputation: 31

To start off, I would recommend that you use the GLUT (GL Utility Toolkit) API. Look it up over here... http://www.opengl.org/resources/libraries/glut/

I think it is the best way to start graphics programming using openGL.

Upvotes: 0

Peter Alexander
Peter Alexander

Reputation: 54270

OpenGL is a library. Your C++ code, which compiles into machine code (for your CPU, not GPU), calls OpenGL functions, which send data to your graphics card (GPU). The graphics card interprets that data, and uses it to do whatever you've asked it to do. The GPU does not run any of your C++ code.

GLSL (OpenGL Shading Language) is a language used to instruct what the GPU's shaders do. Note that the name is a bit of a misnomer, because code written in shading languages do a lot more than shading nowadays. Typically, you will write your GLSL code much like you write your C++ code, then use OpenGL calls to compile the GLSL code, and then use more OpenGL calls to instruct the CPU to use the shader programs.


CPU

C++ code calls OpenGL functions calls Graphics driver code, which transmits instructions to the GPU through hardware.

GPU

Interprets hardware signals received from the graphics driver to run its own internal programs. This may include compiled GLSL programs, which are also sent from CPU in the same way.


Note: You can replace "Open GL functions" with "DirectX functions" and "GLSL" with another shading language and the diagram is the same.

Upvotes: 11

Firas Assaad
Firas Assaad

Reputation: 25750

Simply put, OpenGL is a library that communicates with your graphic card's driver. You call OpenGL functions in C++ which result in commands being sent to the GPU for processing. Your C++ code is always run on the CPU, including all your OpenGL library calls, but the calls are translated to commands that are understood by the graphic card driver.

In the past the GPU had a fixed-function pipeline and OpenGL acted as a state machine where you to enable and disable certain functionality such as specifying the position of a light source or how some image should be mapped to an object. OpenGL is still a state machine, but with programmable shaders you write programs in a C-like language (GLSL) and use OpenGL functions to instruct the driver to compile and link the programs and execute them on the GPU.

A good place to start learning more about OpenGL is OpenGL SuperBible. The latest version doesn't cover the old fixed-function pipelines (where you couldn't write shaders) and requires a somewhat decent video card.

Upvotes: 1

ChrisF
ChrisF

Reputation: 137128

OpenGL and DirectX do the interfacing to the graphics card for you.

You can write the low level code yourself, but I'd recommend getting an understanding of the basics first.

Once you've done that you could look at writing the graphics drivers yourself, but don't expect to beat the performance of the card manufacturers teams of developers.

Upvotes: 7

nathan
nathan

Reputation: 5733

The definitive place for Opengl NeHe. The tutorials here will get you started with the basics.

Upvotes: 2

Related Questions