Mintoris Forum

Author Topic: OpenGL Game Engine  (Read 52680 times)

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: OpenGL Game Engine
« Reply #40 on: Jan 28, 2016, 04:32 AM »
I prefer small case all the time if you look at any of my programs you will notice I do everything in small case.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #41 on: Jan 28, 2016, 05:43 AM »
rasdini, thought you'd like to know, tests today showed the connection to the game engine has to be asynchronous. The interrupt subs will be called by queued messages. The syntax will remain the same as I've described above.

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: OpenGL Game Engine
« Reply #42 on: Jan 28, 2016, 11:33 AM »
I think that is a good call. I have a feeling that it will boost the speed as well. For some reason,  during normal game play, Mintoris executes really fast when an interrupt is called for the touch command. Look at my latest game Pong II. The ball moves really fast as you are sliding the paddle up and down. Take your finger off the screen and the ball slows down.  Can you explain why this happens. I have been racking my brain and all I can come up with is that for some reason the interrupt somehow shuts out all other phone processes for a moment.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #43 on: Jan 29, 2016, 01:57 AM »
Here is today's test program. I only spent about half an hour testing that they at least execute correctly. The testers are doing a great job. I'm sending out today's test build next. Here are the new commands today.

GenMoveSprite sprite, distance{, angle}

GenSetSpriteVelocityX sprite, vx
GenSetSpriteVelocityY sprite, vy
GenSetSpriteVelocityXY sprite, vx, vy
GenSetSpriteVelocity sprite, Velocity{, angle}

GenSetSpriteAccelerationXY sprite, accelX, accelY {, terminalVelocity }
GenSetSpriteAcceleration sprite, acceleration, angle {, terminalVelocity }

GenAccelerateSpriteXY sprite, accelX, accelY{, terminalVelocity }
GenAccelerateSprite sprite, acceleration, angle {, terminalVelocity }

GenSetSpriteTerminalVelocity sprite, terminalVelocity


I actually changed the way that terminal velocity works, so if you get that far terminal velocity needs extra testing.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #44 on: Jan 29, 2016, 02:23 AM »
If the optional angle parameters are not specified the sprite goes in the direction of it's current rotation.

as in:

GenMoveSprite sprite, distance{, angle}

GenSetSpriteVelocity sprite, Velocity{, angle}

I know my test program is lame. I've just got too much work to do under the hood.

Oh, and zero degrees is this way:

->
« Last Edit: Jan 29, 2016, 02:26 AM by Chuck »

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #45 on: Jan 30, 2016, 12:32 AM »
The GenSetSpriteColor command has a problem. Don't use it till I send out the next update. Didn't get much done today. Tomorrow I will start early and get sprite tile animation working.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #46 on: Jan 30, 2016, 01:39 AM »
I think I've been adding commands faster than I've been explaining how the game engine works.

The First rule is that you must execute an Orientation 1 or 2 to fix the screen in portrait or landscape before turning the game engine on.

Orientation 2
GameEngine On, 800, 480, "GameEngine/Loading.png"


That's it, the game engine is on. The 800, 400 is the width and height you want the screen to be. This works like the SetScale command in the graphics mode. These are optional parameters and if omitted will default to the actual size of your screen. Then the "GameEngine/Loading.png" is an optional splash screen that will be displayed until a GenSplashScreen Off is executed.

Next you must set up the graphics that will be shared by all your sprites. (Before you ask it's done this way for maximum speed, flexibility and compatibility with the on-board GPU).

atlas = GenTextureAtlas(1024, 1024)

It's fairly safe to assume that the GPU in your Android device has at least 1mb of on-chip ram. A texture atlas is a way of dividing up that memory for use in your game. You might not need so much and could define a 512 x 512 block of memory. But the size you choose must be 512 x 512 or 1024 x 1024 or any combination of the two.

Atlas' are made up of textures. A texture (in this case) is a graphics block like a bitmap but divided up into tiles.

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




This is an actual texture from my game Mintoris Space. As you can see it is made of a group of 96x96 graphic tiles. A single texture atlas may contain many textures each with differing size tiles.

But, to keep things simple, we create a single texture and put it into our texture atlas.

GenMapToAtlas atlas, texture, 0, 0

Now we load the texture atlas onto the GPU

GenLoadAtlas atlas


The graphics are now set up ready to be used by sprites.

So, we finally create a sprite and use our set of 96x96 images as it's tile set.

sprite = GenSprite(texture)


You can then set which tile to display.

GenSetSpriteTile sprite, 5

You can then use any of sprite commands you want.

Textures can also be created from normal bitmaps.

bitmap = CreateBitmap(960, 480)


draw on the bitmap…

texture = GenTexture(bitmap, 96, 96)


The problem atm is that you have to have the graphics mode on to draw on a bitmap. I plan to fix it so you can create and draw on bitmaps anytime. That will allow run time created graphic elements.


Ask any questions now. You can bet all of this will make it into the reference manual.
« Last Edit: Jan 30, 2016, 02:26 AM by Chuck »

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: OpenGL Game Engine
« Reply #47 on: Jan 30, 2016, 02:33 AM »
So all the sprites in my game must be packed onto one image file? Why can't I use graphics mode in game engine. I'm using sprites, but I still want to draw lines and circles or particles or any number of things. Please explain how to do both, so I can draw on the screen and use sprites.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #48 on: Jan 30, 2016, 02:46 AM »
Yes, I have thought about this. In my game I can't draw lines and such. I can only manipulate these tiles. But, here in Basic I knew that wouldn't be enough.

I haven't got this far yet, but there will be two ways you will be able to use the current drawing commands.

One way is to do a SetDrawingSurface bitmap then do all your drawing on a the bitmap. Then you just update the texture with your bitmap. I'll show you how when I get it all working.

The other thing is Backgrounds. There are several different types of backgrounds in the game engine. Static, Scrolling, Parallax. I though why not create a new kind of background called a Graphics background that you could draw on using the existing graphics commands. So, when you use a Graphics background, it will work the way you want it to. And I'm sure you will find uses for the other types of backgrounds too.

You said you wanted to test as sooon as I had something. All of the good stuff will come slowly over the next few weeks.
« Last Edit: Jan 30, 2016, 02:48 AM by Chuck »

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #49 on: Jan 30, 2016, 08:36 PM »
The following commands will be available in tonight's test build.

GenSetSpriteTexture sprite, texture

GenRemoveSprite sprite
GenReviveSprite sprite
GenResetSprite sprite

GenSetSpriteVisible sprite, On | Off

GenAnimateSprite sprite, startTile, endTile, msDelay (, loops, finalTile }
GenAnimateSpriteRandom sprite, startTile, endTile, msDelay
GenAnimateSpriteCustom  sprite, tileArray(), msDelay (, loops, finalTile }

GenStopSpriteAnimation sprite


I have the feeling that everyone had their own idea of what a game engine was and is now in little shaken by the realities of the game engine I have to offer. This engine is designed to utilize the GPU for maximum speed and flexibility. I have been adding a lot of commands, but only a few are needed to get some graphics on the screen. Gone are the days of hectically looping and redrawing the screen. The GPU takes care of all that in the background. Games written with the new engine will be smaller and do much more. They will set up the graphics and then sit back and wait for events to happen.
« Last Edit: Jan 30, 2016, 08:53 PM by Chuck »

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #50 on: Jan 31, 2016, 01:25 AM »
I actually spent time on the demo program today. I've attached it below. You will need the 1-30-16 build to run this.



Code: [Select]
' Game Engine Demo
' Written by: Charles Charbonneau
' 1/30/16

maxSprites = 20
width = 800
height = 480
spaceLayer = 5

Orientation 2 ' Landscape

GameEngine On, width, height, "Graphics/Loading.png"

atlas = GenTextureAtlas(1024, 1024)
texture = GenTexture("Graphics/textureScene96x96.png", 96, 96)
GenMapToAtlas atlas, texture, 0, 0
GenLoadAtlas atlas

dim sprite(maxSprites)

forward() = [ 1, 2, 3, 4, 5, 6, 7, 8]
backward() = [ 8, 7, 6, 5, 4, 3, 2, 1]

for i = 1 to maxSprites

  sprite(i) = GenSprite(texture)

  if rnd(100) >= 50 then
    GenAnimateSpriteCustom sprite(i), forward(), 100 + rnd(50)
  else
    GenAnimateSpriteCustom sprite(i), backward(), 100 + rnd(50)
  endif

  GenSetSpriteXY sprite(i), rnd(width), rnd(height)

  scale = rnd(1) * 0.5 + 0.25
  GenSetSpriteScale sprite(i), scale, scale

  GenSetSpriteVelocity sprite(i), rnd(50) + 5, rnd(360)

  GenAddSprite sprite(i), spaceLayer

next

GenSplashScreen off
touch x,y

GameEngine Off
Exit
« Last Edit: Jan 31, 2016, 05:41 AM by Chuck »

rendomizer

  • Full Member
  • ***
  • Posts: 87
Re: OpenGL Game Engine
« Reply #51 on: Jan 31, 2016, 08:24 AM »
to use these commands we need to by the upgrade mintoris basic pro ?

nice work it's fantastic  chuck ‼

best regard rendomizer

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #52 on: Jan 31, 2016, 08:28 AM »
This will be a free upgrade to existing users, but I do intend to raise the price of Basic after the upgrade. Right now only a few testers have access to the test version.

If you would like to help test these commands, send an email to support@mintoris.com

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: OpenGL Game Engine
« Reply #53 on: Jan 31, 2016, 03:36 PM »
Chuck, I am having no luck following the demo. I really need comments before every command you are using, why you are doing it and what it is making happen. Simple commands no big deal, position, rotate but what is all the other stuff doing?

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #54 on: Jan 31, 2016, 08:24 PM »
I've gone through and commented each line. Let me know exactly what is causing you the problem. I may be able to simplify things.

I think it is this section that is giving the most problems.

Code: [Select]
'Create the texture atlas
atlas = GenTextureAtlas(1024, 1024)

'Create only one texture from our graphics tiles
texture = GenTexture("Graphics/textureScene96x96.png", 96, 96)

'Put the texture inside the atlas
GenMapToAtlas atlas, texture, 0, 0

'Load the graphics atlas onto the GPU for use
GenLoadAtlas atlas

Maybe I should rename some commands?

Is this easier to understand?

Code: [Select]
'Create the Tile atlas
atlas = GenTileAtlas(1024, 1024)

'Create only one tile set from our graphics file
tileset = GenTileSet("Graphics/textureScene96x96.png", 96, 96)

'Put the tile set inside the atlas
GenMapToAtlas atlas, tileset, 0, 0

'Load the tile atlas onto the GPU for use
GenLoadAtlas atlas

The great part about being in the development phase is that we can still make changes to the command names.

Update: I went ahead and renamed those commands. It just seemed much clearer. So in the next release the following functions will be renamed.

atlas = GenTextureAtlas(1024, 1024)
texture = GenTexture("Graphics/textureScene96x96.png", 96, 96)

to

atlas = GenTileAtlas(1024, 1024)
tileset = GenTileSet("Graphics/textureScene96x96.png", 96, 96)

« Last Edit: Mar 24, 2016, 04:24 PM by Chuck »

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: OpenGL Game Engine
« Reply #55 on: Jan 31, 2016, 10:42 PM »
Yes, I believe simplicity is going to be key if you want it to be something a lot of people use. Too complex and sales will not be there. I have a hard time understanding this Atlas and what it is for. Why not be able to just load images, forget the Atlas. Access is going to be fast with the engine anyway Atlas or not. Just allow us to load all the images we want as long as they don't exceed memory. Images can be numbered 1 on up. Then just use the image numbers in our sprite commands.
example:

genmakesprite s#,image#

genanimatedsprite s#,image#,xsegment,ysegment

As far as drawing goes, can we have gameengine on and add a command to turn the backdrop off? If we do so, then normal graphics mode with bitmap drawing default to screen as usual and can be used right along with the sprites?

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #56 on: Jan 31, 2016, 10:59 PM »
To answer why it's done this way, for top speed the game engine uses the Graphics Processing Unit (GPU). The GPU requires the graphics to be formatted in a certain way. Internally the tile atlas is the correct graphics format to be loaded directly to the GPU's on-chip memory. If you want a high performance game engine, you have to do just a little extra work to put your graphics into the most efficient format.

- A tile atlas may have multiple tile sets each with different tile dimensions.
- A tile atlas allows for the most efficient use of the GPU's on-chip memory.
- You may have several tile atlas' if you need them.

It's not like I have much choice. This is just how OpenGL works.
« Last Edit: Jan 31, 2016, 11:05 PM by Chuck »

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: OpenGL Game Engine
« Reply #57 on: Feb 01, 2016, 01:27 AM »
I'm not understanding how the Atlas works. Do I grab certain parts for each sprite and how do I do that? Is it one big image I'm grabbing parts from, or is it being added to a stack of images in the gpu when you start using the texture command?

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #58 on: Feb 01, 2016, 02:08 AM »
Let me back up. Say for the moment that you have a graphics area 1024 x 1024 and you need to fit all the graphics for your game in that space. A tile atlas is like a map of that 1024 x 1024 area. Within that atlas you have your tile sets. You can think of these as special bitmaps. Each tile set is further divided into tiles. It's these individual tile that get displayed by the sprites.

Below is a page from my notes with a drawing of how I divide up the tile atlas for Mintoris Space.



The tile set from the Game Engine Demo is the same tile set that gets loaded into the atlas above at 0,0 (the upper left corner). It fits nicely into the first 960 x 384 block of the atlas. As you can see the atlas can contain many different tile sets. The 960 x 384 block is divided into 4 rows of 10 tiles, each tile being 96 x 96.



the third and forth rows are blank above.

atlas = GenTileAtlas(1024, 1024)

'Create one tile set from our graphics file
tileset = GenTileSet("Graphics/textureScene96x96.png", 96, 96)

'Put the tile set into the atlas
GenMapToAtlas atlas, tileset, 0, 0

' You could add more tile sets to the atlas at this point

'Load the tile atlas onto the GPU for use
GenLoadAtlas atlas


Once the atlas is loaded onto the GPU you only have to worry about the tile sets.

sprite = GenSprite(tileset)

GenSetSpriteTile sprite, tilenumber

GenAddSprite sprite, layer


Since there are 40 tiles in the tile set, tilenumber may be 1 to 40.

« Last Edit: Feb 01, 2016, 02:25 AM by Chuck »

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #59 on: Feb 01, 2016, 08:44 PM »
I will be adding the following functions next. They are all used to get information about the sprite.

type = GenGetSpriteType(sprite)
tile = GenGetSpriteTile(sprite)
layer = GenGetSpriteLayer(sprite)

tileset = GenGetSpriteTileSet(sprite)

red = GenGetSpriteRed(sprite)
green = GenGetSpriteGreen(sprite)
blue = GenGetSpriteBlue(sprite)
alpha = GenGetSpriteAlpha(sprite)

rotation = GenGetSpriteRotation(sprite)
pivotX = GenGetSpritePivotPointX(sprite)
pivotY = GenGetSpritePivotPointY(sprite)

scaleX = GenGetSpriteScaleX(sprite)
scaleY = GenGetSpriteScaleY(sprite)

X = GenGetSpriteX(sprite)
Y = GenGetSpriteY(sprite)

centerX = GenGetSpriteCenterX(sprite)
centerY = GenGetSpriteCenterY(sprite)

pivotX = GenGetSpritePivotX(sprite)
pivotY = GenGetSpritePivotY(sprite)

width = GenGetSpriteWidth(sprite)
height = GenGetSpriteHeight(sprite)

unscaledWidth = GenGetSpriteUnscaledWidth(sprite)
unscaledHeight = GenGetSpriteUnscaledHeight(sprite)

velocity = GenGetSpriteVelocity(sprite)
velocityX = GenGetSpriteVelocityX(sprite)
velocityY = GenGetSpriteVelocityY(sprite)

Acceleration = GenGetSpriteAcceleration(sprite)
AccelerationX = GenGetSpriteAccelerationX(sprite)
AccelerationY = GenGetSpriteAccelerationY(sprite)

velocity = GenGetSpriteTeminalVelocity(sprite)

angle = GenGetSpriteAngleTo(sprite1, sprite2)
angle = GenGetSpriteAngelToXY(sprite, x, y)

angle = GenGetSpriteDirectionAngle(sprite)

saveCode$ = GenGetSpriteState$(sprite)

isGenSpriteDead(sprite)

isGenSpriteVisible(sprite)

isGenSpriteOnScreen(sprite)

isGenSpriteAtTerminalVelocity(sprite)

isGenSpriteStopped(sprite)

« Last Edit: Feb 03, 2016, 07:32 PM by Chuck »