Archived

This topic is now archived and is closed to further replies.

C programming and graphics

This topic is 5492 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can anyone point me to some simple examples of C programs that make calls to a graphics program (preferably DirectX). I am pretty far into C programming but haven''t found much in the way of giving a C program a GUI (or any other graphics for that matter).

Share this post


Link to post
Share on other sites
C and DirectX is a baaaad combination, since DX is made especially for C++ (tho it works with other languages as well).
If you want C, and graphic + portability and simplicity, try SDL:
http://www.libsdl.org

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
kmne68, if you''re truly interested in coding up a DX app w/C only, i''d suggest taking a look at the "Using C to Access COM Objects" page in the DX 8.1 docs. there''s also a similarly named article in the DX 7.0 docs as well as one in the MSDN library docs supplied w/VC++.

all you really do differently is 1) go through the vtable and 2) provide the pointer to the interface as the first parm in the function call.

e.g.,

C:

hr = lpDD->lpVtbl->CreateSurface (lpDD, &ddsd, &lpDDS,
NULL);

C++:

hr = lpDD->CreateSurface(&ddsd, &lpDDS, NULL);


this is true for any COM object, which is what the DX interfaces provide.

if you don''t care about portability and are only interested in MS Windows GUI, all of the Windows GDI API functions are straightforward C calls.

Share this post


Link to post
Share on other sites
Or since you can compile straight C code in a C++ compiler, you can just use DirectX normally within your program. Just make sure you compile in C++ mode.



Make it work, then
make it fast.

"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book

Share this post


Link to post
Share on other sites
There are also a number of macros defined to make some function calls easier. Have a look in the d3d8.h and you will see lines like


#define IDirect3D8_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
#define IDirect3D8_AddRef(p) (p)->lpVtbl->AddRef(p)
#define IDirect3D8_Release(p) (p)->lpVtbl->Release(p)

Share this post


Link to post
Share on other sites
Thanks to all who responded to my original question regarding graphics calls from C. I guess I should have made clear my intention to delve into C++ very soon. Thanks again.

Share this post


Link to post
Share on other sites