Mintoris Forum

Author Topic: OpenGL Game Engine  (Read 52589 times)

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
OpenGL Game Engine
« on: Sep 30, 2015, 09:45 PM »
I've been thinking. I've got this whole graphics and game engine I developed for Space. With some work it could be added to Basic. I'm only considering this now that we can easily make Apk files from our Basic programs. Because, as soon as I add an advanced game engine to Basic people will want to publish their games.

We would get a new video mode:

GameEngine On

Some of the new objects (Objects like bitmaps are objects)

Texture - A graphics block like a bitmap but divided up into tiles.

TextureAtlas - A collection of Textures that can be stored in the GPUs memory for fast graphic maneuvers. Maximum size of a TextureAtlas is 1024x1024. You may have more than one Texture atlas but swapping them into the GPU slow down the fps.

Sprites - The basic graphics unit. Sprites are made up of graphic tiles from the TextureAtlas. Lots of automatic functions like movement, bouncing off object it collides with, auto spinning, scaling, etc. Any sprite can also act as a button.

Scenes - A scene would be one level of a 2D game. Handles a tiled, scrolling background as well as tiled layers above. A scene can have many graphic layers and sprites can be put in any of them.

The only problem I see is linking events Back to Basic. Like when two sprites collide you would need an onCollide(sprite) sub to be called automatically as an interrupt. The problem would be that the OpenGL graphics would be running so much faster than the Basic code. I wouldn't be able to pause the OpenGL graphics to process the onCollide(sprite) sub. Which would mean that onCollide would be called asynchronously and may be still executing several frames after the collision occurred.

This is a fairly ambitions project and it may take me some time to complete. Maybe a month or more once I start. I have to say that doing this project will depend on how Basic sales go with the new Export Apk Project feature.  
« Last Edit: Sep 30, 2015, 09:51 PM by Chuck »

zakerytclarke

  • Sr. Member
  • ****
  • Posts: 195
Re: OpenGL Game Engine
« Reply #1 on: Oct 01, 2015, 02:26 AM »
I've always wanted advanced  graphic capabilities in mintoris. I think the collision events could be tested in an if statement

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #2 on: Oct 01, 2015, 04:00 AM »
To get the real speed, collision detection has to be done by the engine. I think the asynchronous method will work. Right now you can get graphics at 12-20 fps. I'd like to see 50-60 fps.

hoyoyo80

  • Full Member
  • ***
  • Posts: 66
Re: OpenGL Game Engine
« Reply #3 on: Oct 03, 2015, 10:56 AM »
Wow‼‼ Looking forward for this one. I wonder if my next project require game engine or not. I want to make a drag and drop basic shape to sketch a layout for hawkers stalls layout. ;D But maybe graphics mode can achieve this  but i havent explore that part.

zakerytclarke

  • Sr. Member
  • ****
  • Posts: 195
Re: OpenGL Game Engine
« Reply #4 on: Oct 03, 2015, 03:41 PM »
To get the real speed, collision detection has to be done by the engine. I think the asynchronous method will work. Right now you can get graphics at 12-20 fps. I'd like to see 50-60 fps.

I tried to create a sprite include file about a month ago, but the graphics rendered too slowly, causing flickering and collision detection  seemed impossible. I think you're right and these will have to be implemented  directly in the language.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #5 on: Nov 29, 2015, 03:53 AM »
I've been giving this topic a lot of thought. I think adding my game engine to Basic would be the single best thing I could do to promote the app. As I see it right now, it's a two phase upgrade. I have to add event handling to Basic before I can add the Game Engine.

Event onTouch(action, index, x, y)

  return true
End Event



Event onCollision(Sprite1, Sprite2)

End Event


Everything in the game engine is event driven.

The other thing is that the existing game engine is designed for Space games. But, I think with a little work it could be adapted to Mario/maze game formats. All 2D of course.

Oh, and regular graphics mode commands will not work in the game engine except by drawing on a bitmap that could be used as a graphics tile. Everything will be tile based Sprites.
« Last Edit: Nov 29, 2015, 04:00 AM by Chuck »

sraffens

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 220
Re: OpenGL Game Engine
« Reply #6 on: Nov 29, 2015, 07:46 PM »
This will be great features for basic.

I look forward to commands and demos.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #7 on: Nov 30, 2015, 02:07 AM »
It's a big project. It all depends on me getting the Events working. I think I might get started in January.

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: OpenGL Game Engine
« Reply #8 on: Dec 09, 2015, 01:33 AM »
as a suggestion chuck, could you not create a reference that is updated at opengl speeds, so no matter when we look for a spite collision, it is either 1 or 0 no matter when we look from Mintoris. a second reference could store the value of the other sprite it collides with. Get Sprite Collision (sprite1,sprite2). sprite1 is our object sprite and sprite2=what sprite is object sprite colliding with. Get Sprite Collision (1,5) returns 1 if 1 and 5 are colliding. Get Sprite Collision (1,0) means sprite1 and any sprite. so (1,0) returns a number equal to the first sprite it detects a collision with. I'm thinking the game engine command should be Get Sprite Collision (s1,s2). if s2 is set to zero then returns value of the first sprite it collided with last engine refresh. I could be way off, I don't know.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #9 on: Dec 09, 2015, 01:49 AM »
Sounds a little too complicated. A collision state only happens for a brief moment. Think about the condition where one Sprite1 collides with Sprite2 and rebounds and hits Sprite3.

I think the event driven routine will work fine. I really don't see a need for a getCollision() command. I expect the frame rate to be pretty high. A collision flag would only be set for a small fraction of a second. I think it's best to just process the collision event at the moment of the collision. You could always set whatever flags you want in your basic code. In fact that would be best since you want the collision event to be as small and as quick as you can make it.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #10 on: Jan 06, 2016, 11:13 PM »
I actually pressed the button today‼ I was just going to look at the code, but ended up fully merging the entire game into Basic. It went a lot easier than I thought. Of course I haven't created any new commands to test it yet. I think tomorrow I will try turning on & off the GameEngine mode. I've been reviewing the features as I worked. If this works out Basic will take a huge step forward.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #11 on: Jan 14, 2016, 02:56 AM »
I've changed my mind on how interrupts will work. Instead of adding new interrupt syntax you will use standard subs and tell Basic which subs are interrupts. As in:

Code: [Select]
setSpriteFrameUpdate sprite, onFrameUpdate

Sub onFrameUpdate( sprite, msSinceLastFrame)

  setSpriteFade(sprite, percent)

End Sub

That way each sprite can have a unique interrupt and multiple sprites can use the same sub as an interrupt.


I think it was a really good idea to just sit and think about this expansion for a few months longer. It's going to be a much better game engine for the wait.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #12 on: Jan 21, 2016, 12:20 AM »
Today I was able to turn the screen green. Not only that, I was able to switch seamlessly between the game engine mode, graphics mode and the regular text mode. I also hooked in the existing Orientation command to set the game mode orientation.

Code: [Select]
Orientation 2
GameEngine On
Wait 10000
GameEngine Off

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #13 on: Jan 22, 2016, 02:50 AM »
I hooked up the splash screen feature and added a command to turn it on and off.

GameEngine ON {, width, height, SplashScreenPath$ }

… Do time consuming loading/setup.

GeSplashScreen Off

… Then later you can turn the splash screen back on or switch to a new splash screen.

GeSplashScreen On{,SplashScreenPath$}
« Last Edit: Jan 22, 2016, 02:53 AM by Chuck »

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #14 on: Jan 23, 2016, 12:54 AM »
Added a couple features today.

GeBackgroundColor red, green, blue

and

Texture = GeTexture(ImagePath$)

Texture is a new type of object variable.
Textures are images in a format ready to be loaded onto the GPU. Textures contain tile graphics which will later be used by sprites as a static image or a set of tiles can be used to animate the sprite‥

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #15 on: Jan 24, 2016, 12:30 AM »
Long day today. Decided to change the Game Engine command prefix from Ge to Gen. Got the first sprite to display today. The demo program is growing.

Code: [Select]
Orientation 2
GameEngine On, 800, 480, "GameEngine/Loading.png"
GenBackgroundColor 0,0,0

atlas = GenTextureAtlas(1024, 1024)

texture = GenTexture("GameEngine/textureScene96x96.png", 96, 96)

GenMapToAtlas atlas, texture, 0, 0

GenLoadAtlas atlas

sprite = GenSprite(texture)

layer = 5
GenAddSprite sprite, layer

GenSplashScreen Off
Wait 5000
GenSplashScreen On
Wait 5000
GameEngine Off
« Last Edit: Jan 31, 2016, 01:56 AM by Chuck »

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: OpenGL Game Engine
« Reply #16 on: Jan 24, 2016, 06:16 AM »
Sounds good Chuck. Keep up the good work.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #17 on: Jan 24, 2016, 07:33 AM »
Let me know if you got that test version to run. I think after tomorrow you will be able to do something useful.

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: OpenGL Game Engine
« Reply #18 on: Jan 24, 2016, 07:47 AM »
It's up and running. Seems to be working fine. Had to add the GameEngine folder and paste the necessary images into that folder. Will all images used by the game engine reside there? If so, does this affect making apk's? Just curious.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #19 on: Jan 24, 2016, 07:49 AM »
No, I just made that dir for the demo. But, creating a dir for each program is a good idea since you have to do it anyway to create an apk.
« Last Edit: Jan 24, 2016, 07:56 AM by Chuck »