🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Game in pure C99

Started by
8 comments, last by Dawoodoz 9 years ago

I need a framework for my own programming language so that I can test it with real interfaces but haven't found anything for over a year now.

Is there any graphical C99 code sample based entirely on the Windows API and DirectX without any static linking?

I tried to integrate parts of SDL but can't take out one thing without pulling out the whole framework.

Advertisement
Without static linking, you have to manually decode a bunch of COM interface details and build function pointer tables. Honestly if you want to do a pure dynamic loader, it will be much easier to use OpenGL, as it is a pure C API.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

Without static linking, you have to manually decode a bunch of COM interface details and build function pointer tables. Honestly if you want to do a pure dynamic loader, it will be much easier to use OpenGL, as it is a pure C API.

That could work. smile.png

Slightly off-topic, but there aren't many game engines based on C99 out there..

I've managed to find two, however: DarkHammer and Corange.

Have been meaning to do some game programming in pure C for quite a while now.. :)

Too many projects; too much time

Really, there aren't that many APIs needed to be imported from DLLs for using DirectX. For Direct3D all you need is one of the CreateDevice functions. From there on, it's all COM calls which are dynamically linked at runtime (in addition to what Promit said, but see the last paragraph here about the interface definitions from the DirectX SDK headers).

The harder part is statically linking to static libraries, like the DirectXMath functions, which are intentionally distributed as a static-only .libs, with inline functions, in order to allow the compiler to optimize through them for speed.

In fact, most of the DirectX examples on MSDN are C-only code (maybe they do use typedefs an other C++ constructs sometimes, but mostly they're always careful not to post code that depends on any C++-only libraries, except for where it's specifically required, like for C++ frameworks like the Effects framework), and the DirectX headers provide interface defintions for use with C-only programs. Only the samples provided with the DirectX 2010 SDK were C++, IIRC (and most samples from other SDKs too).

Are there any good tutorial for calling OpenGL directly without any GLUT or math library?

My compiler only outputs one giant string of C code to be compiled and should not have a too long list of things to do in order to compile the C code on different compilers for the programmer.

It sounds to me that you think you can somehow automate the inclusion of dependencies for either DirectX or OpenGL in a generated C file (or project)?... or get rid of them completely?

You won't be able to do that.

You will have to at least include the OpenGL or DirectX headers in your generated C code, and then link the compiled .obj with the the .lib files for DirectX/OpenGL.

So you have two problems to tackle:

1) Using the header files with any C compiler - the problems here are mostly due to different pre-processor definitions being supported by different compilers. Microsoft's C compiler also adds some extensions on top of the ANSI C standard which may not be supported by any other C compiler. I don't think any of these are used in the DirectX headers though.

2) Linking the compiled code against the DirectX/OpenGL libraries - you have not specified anything about how you expect to link your code, but if you can't use .lib files (or the older .DEF files) for imported function tables, then you'll have to come up with another way to do this. Like I said before, form this point of view, it should be easier to use DirectX, because it only has one function to import (and a few more for things like enumerating display adapters and such, but I don't think it has more than 10 API functions, and you will probably only need to use at most one or two in your project)... You do not even have to link to any .lib files for this... you can use the LoadLibrary/GetProcAddres Win32 functions to get a pointer to the DirectX API functions. OpenGL is not a COM-based API, so it requires linking (or using a lot of LoadLibrary/GetProcAddress calls) in order to get it's API functions imported within your project.

I tried using GetProcAddress a few months ago in an attempt to load an ActiveX component but could not find out how to connect the loaded component to a window.

If it gets messy, I can modify my language to hide the complexity.

ActiveX components and other similar OLE-based COM objects are initialized differently from DirectX. DirectX has it's own Create*Device function that creates the initial "device" COM object, which you then use to create other COM objects for handling resources.

In order to use ActiveX controls, I think you would need to implement a COM object yourself, which is bound to your window, and provides specific interfaces to the ActiveX objects.

ActiveX components and other similar OLE-based COM objects are initialized differently from DirectX. DirectX has it's own Create*Device function that creates the initial "device" COM object, which you then use to create other COM objects for handling resources.

In order to use ActiveX controls, I think you would need to implement a COM object yourself, which is bound to your window, and provides specific interfaces to the ActiveX objects.

I made my graphics engine as an ActiveX component in C++ because it had a ready to use MFC template in Visual Studio.

Maybe I can just make a multi purpose framework and use it for everything non console like Visual Basic 6 did but static.

This topic is closed to new replies.

Advertisement