Author Topic: SGDK 2.1 - OpenGL Support  (Read 295486 times)

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
SGDK 2.1 - OpenGL Support
« on: 2008-01-14, 06:45:25 AM »
I am beginning work on SGDK version 2.1 in which I'll try to switch to and/or add support for OpenGL.  So far I managed to write a small test program based on CsGL (C# wrapper for OpenGL) that draws an image on the screen, but it ignored the transparency info, so things are progressing slowly.  If any OpenGL experts out there would like to offer their assistance, it would be appreciated.

I'm also upgrading the SGDK2 project to work in the Visual C# 2008 Express environment so that everyone can easily edit/use/debug the program and their generated games in a freely downloadable, full-fledged development environment.  This also means it will use a newer version of the .NET framework, so Vista users won't have as hard a time downloading an old framework.

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: SGDK 2.1 - OpenGL Support
« Reply #1 on: 2008-01-14, 08:29:51 AM »
good to hear.
but could you give me an example of
everyone can easily edit/use/debug the program and their generated games

i can't imagine what these concretely means.

Jam0864

  • Contributor
  • Fanatic
  • **
  • Posts: 744
    • MSN Messenger - marmalade0864@hotmail.com
    • View Profile
    • Jam0864's Content Dump
    • Email
Re: SGDK 2.1 - OpenGL Support
« Reply #2 on: 2008-01-14, 09:59:32 AM »
so this means sgdk2 and it's games could run on linux/mac?

Richard Kain

  • Regular
  • **
  • Posts: 23
    • View Profile
Re: SGDK 2.1 - OpenGL Support
« Reply #3 on: 2008-01-14, 11:45:21 AM »
Sounds great. OpenGL integration would considerably increase the chances of cross-platform development. It stinks that you are having trouble at the moment. Transparency and full PNG support is one of the best things about SGDK2. I can't imagine going without it. Unfortunately, I am primarily a C# programmer, and have little experience with OpenGL. I hope you are able to find a little help for this. Support for Visual C# 2008 is nice, though I think updating it to work with the latest version of the .NET framework is probably more important.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: SGDK 2.1 - OpenGL Support
« Reply #4 on: 2008-01-14, 12:27:46 PM »
good to hear.
but could you give me an example of
everyone can easily edit/use/debug the program and their generated games

i can't imagine what these concretely means.

The games generated with SGDK2 are somewhat different than those built with SGDK1.  Rather than being in a GDP file that requires GDPlay.exe or gamedev.exe to run, it actually writes all of the source code in C# to files, then compiles it into a single standalone executable.  Those files are not deleted after the compile is complete, however.  You can open the project in Visual C# 2008 Express and edit all of the code that runs the game directly, including the code from the Source Code folder as well as all of the generated code based on sprite rules, plan rules, and so forth.

This gives a better debugging environment for finding errors when developing your own source code, since you can step through the program line by line to see where problems crop up.
Edward Dassmesser

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
OpenTK
« Reply #5 on: 2008-01-18, 12:54:40 PM »
I took a few missteps at the beginning here, but I suppose one should expect to research a few technologies before settling on one.  I first tried CsGL, which was last updated in 2002, but seemed like it must at least be stable.  Then I discovered Tao.OpenGL, and started looking into that.  But I was concerned about the portability of that since it required Tao.Platform.Windows.dll, which doesn't exist on other platforms.  I think I've finally settled on OpenTK for the OpenGL wrapper that I'll be using.  I converted my test program to use that and it works nicely.  Next I'll start editing SGDK2 code.  OpenTK looks like it's very careful about cross-platform support.  It's in alpha right now, so it's not necessarily fully implemented or stable, but it least it should be up-to-date.  And I can pull in updated versions as they become available.

Richard Kain

  • Regular
  • **
  • Posts: 23
    • View Profile
Re: SGDK 2.1 - OpenGL Support
« Reply #6 on: 2008-01-18, 01:46:42 PM »
Hmmm...that makes me think of something. One of the things I've been wanting to do with SGDK2 is create a game with a non-standard screen aspect ratio. That is to say, it would be vertically oriented, rather than the standard 4:3. I would want to do this because I am interested in using SGDK2 to create a shmup. And many shmups scroll upwards and have vertically oriented screens. (screens that are taller than they are wide) The existing source code doesn't allow for this, and I can't seem to save edits that I make to the source code either. But I know from looking at the source code that this should be possible. Can I fire my game up in Visual Studio and add new screen resolution options?

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: SGDK 2.1 - OpenGL Support
« Reply #7 on: 2008-01-18, 03:23:56 PM »
If you want to save your edits to the source code, you have to edit it within the SGDK2 IDE, or edit it in Visual Studio and then copy your edits into the proper file in the SGDK2 project's SourceCode folder in the IDE.  Each time the game is compiled, all the files in the generated project folder are overwritten by content that is generated based on the SGDK2 file.  However, if you happen to be editing code that is not contained in the source code folder in SGDK2 (because it's one of the few bits that are hard-coded into the code generator) then yes, your only choice is to load the project into Visual Studio and edit it there.  Of course the you can never compile your project in SGDK2 again without overwriting what you did... you would have to re-apply your changes every time you compile from SGDK2.

On the topic of screen size, though, I noticed an interesting thing while working on my OpenGL test program.  It's really easy to make the screen resizable and have the contents stretch to fill the window.  Maybe I'll allow that in 2.1 instead of making the window a fixed size.  Also, it'd be kinda cool to be able to zoom out in the map editor!  I could really open up control over sizes and aspect ratio.  You could define any size screen that you want to work with, and then if it doesn't fit the display, it can just be scaled.  I suppose I'll need two sizes: Game Size for defining how much graphics you want to fit on the screen (640x480 pixels worth for example), and Viewport size for defining how big it should be displayed (by default).  Viewport will change as the window size changes, and will have to fit a full screen resolution if the player switches to full screen (though that's not supported in OpenTK yet). I wonder if there's a better term for "Game Size".

BTW, I'm thinking full screen is not such a necessary feature... do many people find that important?  I suppose it might improve performance in some environments, but ideally, I think a lot of people like to play within a window.

Ooh, I think "Native Size" might be a good term instead of "Game Size"

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: SGDK 2.1 - OpenGL Support
« Reply #8 on: 2008-01-18, 03:48:45 PM »
please don't delete the fullscreen option...
how about playing the game in 800x600, while the rest of the screen is black? is there a possibility for that? i would think that is a cool thing, because some games would blur at fullscreen, but always having the normal desktop background while playing annoys me.

giving the user control over screen sizes is a good thing. a few months earlier i saw i quite cool game in extreme wide format. maybe 100px high, but 800 wide. that was cool!  :laugh:

Jam0864

  • Contributor
  • Fanatic
  • **
  • Posts: 744
    • MSN Messenger - marmalade0864@hotmail.com
    • View Profile
    • Jam0864's Content Dump
    • Email
Re: SGDK 2.1 - OpenGL Support
« Reply #9 on: 2008-01-18, 07:48:03 PM »
zooming in and out in the map editor would be great!  ;D

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: SGDK 2.1 - OpenGL Support
« Reply #10 on: 2008-01-19, 02:01:37 AM »
zooming in and out in the map editor would be great!  ;D

word.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: SGDK 2.1 - OpenGL Support
« Reply #11 on: 2008-02-05, 08:41:51 PM »
Good News! Just now I managed to get the map editor up and running on OpenGL, scrolling and all, and all the sample game's tiles were showing up.  It was a bit blurry (unnecessary anti-aliasing going on?) and I'm not sure the colors were as nice as they should have been, but hopefully I can resolve these issues with further testing and refining.  The tile animation preview is also running on OpenGL.
Woohoo  :nerd:

Edit: BTW, for anyone following the source code, there's a new branch for 2.1 in the subversion repository at branches/SGDK2IDE2.1/
That's where I just checked in my progress with OpenGL.  Note that I did not include OpenTK.dll in source control so you'll have to get that separately.
« Last Edit: 2008-02-05, 08:51:31 PM by bluemonkmn »

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: SGDK 2.1 - OpenGL Support
« Reply #12 on: 2008-02-08, 06:14:09 AM »
I've worked out all the problems I'm aware of in the IDE so things are working pretty much like they did with DirectX.  Next step is to transfer all these updates into the project templates so the projects are using DirectX.  Still not sure if OpenTK supports switching between full screen and windowed mode, though.  It looks like they intend to, but it wasn't implemented in the last version I downloaded.  I'll check again and maybe post a message to see if they are implementing it soon.  It's probably not so important for the IDE, but might be more relevant to the generated games.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: SGDK 2.1 - OpenGL Support
« Reply #13 on: 2008-02-18, 06:41:57 AM »
In the process of implementing OpenGL in SGDK2, I've noticed that OpenTK has a few shortcomings (isn't done yet), so I've started to investigate and experiment with OpenTK code a bit, and may be contributing to the OpenTK project as well.  Namely, some of the text drawing features in OpenTK are incomplete.  I've already suggested an alternate/improved mechanism for positioning text characters when preparing text for drawing.  We're still working out the details of what code is ideal for that (needs to be clean and optimized).

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: SGDK 2.1 - OpenGL Support
« Reply #14 on: 2008-03-15, 01:32:30 PM »
Well, I finally got a few hours to work on the OpenGL conversion, and now I have SGDK 2.1 functioning well enough to generate, compile and run the sample project without any references whatsoever to DirectX.  There's still a problem with drawing messages because the OpenTK text drawing functions aren't done yet.  But all the tile and sprite drawing look good, and the DirectInput references have been replaced with API calls and input devices seem to be working OK.

On the down side, I don't think it's going to be straightforward to continue to support DirectX.  OpenGL/OpenTK have a nice mechanism to draw transformed frames by specifying the corners of the output quadrilateral whereas with DirectX I had to use a transformation matrix to draw a transformed frame.  That affects one aspect of the code generator -- it needs to know that frames are constructed using corners instead of matrices.  But I don't think I want to support both mechanisms unless it's really important.  How would folks feel about it if I abandon DirectX support?

The code is checked into SVN for anyone eager to see how it looks/performs.  It's not quite finished yet, though.