Starting on the porting…
That title might be an overstatement…
I want to make “Gateway” available in multiple platforms, more precisely Windows, Linux and Mac.
Problem is that it was created on top of Cantrip, my small-scale engine for jams and 48-hour compos, which isn’t exactly “cross-platform”… It couldn’t be further from that… Number one, it’s built using a DirectX 9 renderer, so that needs to go, replaced by the multi-platform OpenGL.
I’ve not touched OpenGL for more than 10 years… which is a problem when you need to port something!
Anyway, I’ve decided to start there: porting the Windows version of Gateway from Direct3D 9 to OpenGL 3.2. The reason for OpenGL 3.2 is that it seems to be the closest to Direct3D 9 in terms of features, etc…
After looking for tutorials and such, I found these, but as most tutorials, they tend to gloss over the parts that interest me to focus on the more “newbie” stuff, like what’s a shader, etc…
Anyway, they’ve been useful to at least guide me…
A problem with my study of OpenGL is that I don’t want/like to use libraries like GLUT or GLW… So, I need to delve into these, because most people use them, at least for tutorials!
First step was getting OpenGL compilation working on my development machine… I started by making just an application to create a window:
Impressive, I know…
Then I ran into the first problems, which is “where can I find the include files for OpenGL?”… Most everywhere I saw, they said “it’s installed with Visual Studio, just do #include <gl/gl.h>”, but that didn’t have the binds I needed (in particular glGenVertexArrays (necessary to create the VAO, which I’m not sure I know what it is, but it’s apparentely needed).
After a lot of searches, I decided to give in and use a library: GLEW, which handles the extensions and versions of OpenGL. You can get it at http://glew.sourceforge.net/.
Then I reached the second problem: it was throwing an error on initialization “Missing OpenGL version”… After some searches, I found out I was missing a context, which is basically the bind between the window and OpenGL… Most tutorials I saw didn’t show anything about this, because they use libraries like GLW or SDL to create the window itself…
Just needed to create the following piece of code to do the bind and create the context:
// Create OpenGL context PIXELFORMATDESCRIPTOR pfd; memset(&pfd,0,sizeof(PIXELFORMATDESCRIPTOR)); pfd.nSize=sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion=1; pfd.dwFlags=PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_SWAP_EXCHANGE; pfd.iPixelType=PFD_TYPE_RGBA; pfd.cColorBits=32; pfd.cDepthBits=24; pfd.cStencilBits=0; HDC hdc=GetDC(window->get_window()); int pixel_format=ChoosePixelFormat(hdc,&pfd); SetPixelFormat(hdc,pixel_format,&pfd); wglMakeCurrent(hdc,wglCreateContext(hdc));
With this (and some other tutorial code), I finally got this:
Yep, even more impressive…
And after some more digging, I got my first shader working:
It only outputs red, but it’s a start… most of the code for this was actually boilerplate (read a file, etc)…
And that’s my current point… still a long way to go…
Anyway, my opinion about the OpenGL API remains unaltered… The code ends up ugly (compared to an object oriented API, but I guess that’s expected, since this is a C API for cross-platform development), but the feeling you’re using a global object you’re modifying really annoys me… :\
I still need a million questions answered before I can really start thinking on the porting… For example, OpenGL inverts the Z-axis, so I’ll have to do some stuff in the shaders to do it the other way around, which might get complicated really fast…
Need to figure what’s the equivalent to D3D9’s Vertex Buffers (I think VBOs, but I need to research more), and there’s the whole trouble of loading DDS textures (D3DX currently does that for me, but I can’t use for obvious reasons!).
Also want to see if I can use hlsl2glsl to do the shaders, since I don’t care much about the GLSL syntax and I already have a lot of HLSL shader code done in both Cantrip and Spellbook.
All in all, a lot of work ahead of me…
Now listening to “Top Gun OST”
Link of the Day: Comparison of shots before and after CGI is added… The slider bar makes this awesome: http://www.buzzfeed.com/awesomer/support-your-local-sfx-shop
Comment
You must be logged in to post a comment.