Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    4
  • comments
    13
  • views
    850

Let's start

lilington

891 views

Hi everybody,

After my first game and story, it is time to start the new one with more experience this time.

The primary goal is to avoid the same mistakes, so I will start to talk about it now. It is not the very beginning as I already have 11000 lines of codes. From Soul of Mask experiences, I learn that I should talk about my game as soon as possible. So I will introduce the new game to my two favourite forums GDN and another one in French:

  • Game name: Not sure about it yet and it is not so important now.
  • Game genre: Platform, Adventure. (kind of limbo and Ninja Gaiden mixt)
  • Programming: C core engine, C or C++ game (not decided yet)
  • Graphics: 2D/3D.
  • Graphics lib: OpenGL > 3.5
  • Audio: Not sure yet (probably OpenAl)
  • Platforms: for the moment Windows 10 and Linux (other may come later or not)
  • Relative to the game ( story, artwork, ....): As I said it didn't start already, but story big picture is finished.

So what am I doing now?

I am finishing the first part that will make me decide if I continue the project or not. It is essentially technical like object collision, sprite animation, learning more about platform game technic...

What did I do?

Well, I decided to not use SDL2 as I want to port my game in some platform that does not support SDL. So I choose OpenGL. Plus I plan to use some 3D features in the game. So I mocked SDL2 behaviour and write it very specifically for my game.

bkp.png.32e2768539a9c2e6716f260c39af9e62.png

Here is a screenshot that shows objects rotating. I used a sprite sheet from Soul of Mask, we can also see a red box and a rectangle coming from a function call drawRectangle (more details soon)

here we can see the code I will need to write for an animation:

   bkp_graphics_2dReady(BKP_TRUE);

    BKP_Rec dest,src;
    BKP_Rotate r;
    src.w = 64; 
    src.h = 64; 
    src.x = 2;
    src.y = 2;

    dest.w = 92; 
    dest.h = 92; 
    dest.x = 500;
    dest.y = 200;

    static float iii = 0;
    static double tm = 0;
    static double ta = 0;
    static int alpha = 255 ;
    static int dal = 2;
    tm = glfwGetTime();
        
    //animation timers
    if(tm - ta > 64.0f / 1000.0f)
    {   
        ta = tm; 
        iii += .125;

        if(alpha <=0 || alpha >=255)
            dal = -dal;
        alpha += dal;
    }

    r.center.z = 0;
    r.angle = -iii;
    r.center.x = dest.x + dest.w / 2;
    r.center.y = dest.y + dest.h / 2;
        
    bkp_graphics_drawSurface(G[0] ,&dest,&src,&r,BKP_GRAPHICS_FLIPNONE, &alpha);
        
    dest.w = 368;
    dest.h = 138;
    dest.x -= 35; 
    dest.y -= 20; 
    bkp_graphics_2dsetColori(255,255,255,255);
    bkp_graphics_drawRectangle(&dest, BKP_FALSE);

    dest.w = 168;
    dest.x = 250;
    r.angle = iii;
    bkp_graphics_drawSurface(G[2] ,&dest,&src,&r,BKP_GRAPHICS_FLIPH, NULL);

    r.angle = -iii /4; 
    bkp_graphics_drawSurface(G[0] ,&dest,&src,&r,BKP_GRAPHICS_FLIPV, NULL);

    dest.x = 620;
    bkp_graphics_2dsetColori(255,0,0,255 / 2); 
    bkp_graphics_drawRectangle(&dest, BKP_TRUE);
        
    bkp_graphics_2dFlush();

Looks a little bit like SDL. In this example we can see all the job done so far, Scaling, Positioning, FLIP (vertical, horizontal), Rotate around a point and transparency. Those are all I used with SDL2 so far for Soul of Mask. The first objective is checked. Here is a video that illustrates it:

 

bkp-2018-03-01_15.32.12

   I don't go into the deep details about how I did things, but if people request it in the comments I will, I mean I would like to share it as I think some people who use OpenGL better than I do may give me some precious pieces of advice and improve the way I did it, in the meantime more beginner than I am will have a hint to start. 

Time for a little of performance:

The graphics engine is able to draw on those 3 differents devices (here GPU integrated in CPU)

  - draw a frame in 0.016 ms for 1700 animated sprites on a Intel(R) Core(TM) i5-4210U CPU 1366x768

  - draw a frame in 0.016 ms for 1000 animated sprites on a Broadwell Intel Core M-5Y70 HD 4k

  - draw a frame in 0.016 ms for 7000 animated sprites on a Intel(R) Core(TM) i7-7700 CPU 1920x1080

I didn't test it with a Nvidia or Radeon graphics card yet, for the moment it is irrelevant but it will come later.

 

Conclusion on using custom vs SDL2

pro: Faster. I know everything behind it.

con: Fewer features, less flexible, unoptimized and probably full of bugs I didn't notice yet.

 

I also added a log system I didn't have it for my previous game so at any crash I add to try to reproduce it very hard now it is better just have to read log file on crashes.

here is the output of this video:

DEBUG set
Moving to directory `../`
[ INFO  ][ 2018-03-01 15:27:06] -> Starting Graphics Engine ...
[ INFO  ][ 2018-03-01 15:27:06] -> Starting GLFW 3.2.1 X11 GLX EGL clock_gettime /dev/js Xf86vm shared
[ INFO  ][ 2018-03-01 15:27:06] -> Monitor info:
[ INFO  ][ 2018-03-01 15:27:06] -> #1 1920x1080
[ INFO  ][ 2018-03-01 15:27:06] -> #0 1366x768
[ INFO  ][ 2018-03-01 15:27:06] -> --------------------------

[ INFO  ][ 2018-03-01 15:27:06] -> GL Context Params : 
[ INFO  ][ 2018-03-01 15:27:06] -> GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS : 192
[ INFO  ][ 2018-03-01 15:27:06] -> GL_MAX_CUBE_MAP_TEXTURE_SIZE : 16384
[ INFO  ][ 2018-03-01 15:27:06] -> GL_MAX_DRAW_BUFFERS : 8
[ INFO  ][ 2018-03-01 15:27:06] -> GL_MAX_FRAGMENT_UNIFORM_COMPONENTS : 16384
[ INFO  ][ 2018-03-01 15:27:06] -> GL_MAX_TEXTURE_IMAGE_UNITS : 32
[ INFO  ][ 2018-03-01 15:27:06] -> GL_MAX_TEXTURE_SIZE : 16384
[ INFO  ][ 2018-03-01 15:27:06] -> GL_MAX_VARYING_FLOATS : 128
[ INFO  ][ 2018-03-01 15:27:06] -> GL_MAX_VERTEX_ATTRIBS : 16
[ INFO  ][ 2018-03-01 15:27:06] -> GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS : 32
[ INFO  ][ 2018-03-01 15:27:06] -> GL_MAX_VERTEX_UNIFORM_COMPONENTS : 16384
[ INFO  ][ 2018-03-01 15:27:06] -> GL_MAX_MULTISAMPLE_COVERAGE_MODES_NV : 0
[ INFO  ][ 2018-03-01 15:27:06] -> GL_MAX_SAMPLES : 8
[ INFO  ][ 2018-03-01 15:27:06] -> GL_MAX_MULTISAMPLE_COVERAGE_MODES_NV : 32768 : 32768
[ INFO  ][ 2018-03-01 15:27:06] -> GL_MAX_SAMPLES : 0
[ INFO  ][ 2018-03-01 15:27:06] -> --------------------------

[ INFO  ][ 2018-03-01 15:27:06] -> Opening window with GLFW3 [OK]
[ INFO  ][ 2018-03-01 15:27:06] -> Renderer : Mesa DRI Intel(R) Haswell Mobile 
[ INFO  ][ 2018-03-01 15:27:06] -> OpenGL version : 4.5 (Core Profile) Mesa 17.2.4
[ INFO  ][ 2018-03-01 15:27:06] -> 4.5
[ INFO  ][ 2018-03-01 15:27:06] -> program 3 GL_VALIDATE_STATUS = 1:
[ INFO  ][ 2018-03-01 15:27:06] -> ------------- shader programme 3 info ---------------
[ INFO  ][ 2018-03-01 15:27:06] -> 		GL_LINK_STATUS = 1:
[ INFO  ][ 2018-03-01 15:27:06] -> 		GL_ATTACHED_SHADERS = 2:
[ INFO  ][ 2018-03-01 15:27:06] -> 		GL_ACTIVE_ATTRIBUTES = 1:
[ INFO  ][ 2018-03-01 15:27:06] -> 		0) type:vec3 name: vp location: 0
[ INFO  ][ 2018-03-01 15:27:06] -> 		GL_ACTIVE_UNIFORMS = 2:
[ INFO  ][ 2018-03-01 15:27:06] -> 		0) type:mat4 name: matrix location: 0
[ INFO  ][ 2018-03-01 15:27:06] -> 		1) type:vec4 name: color location: 1
[ INFO  ][ 2018-03-01 15:27:06] -> ------------- end info ---------------
[ INFO  ][ 2018-03-01 15:27:06] -> program 6 GL_VALIDATE_STATUS = 1:
[ INFO  ][ 2018-03-01 15:27:06] -> ------------- shader programme 6 info ---------------
[ INFO  ][ 2018-03-01 15:27:06] -> 		GL_LINK_STATUS = 1:
[ INFO  ][ 2018-03-01 15:27:06] -> 		GL_ATTACHED_SHADERS = 2:
[ INFO  ][ 2018-03-01 15:27:06] -> 		GL_ACTIVE_ATTRIBUTES = 2:
[ INFO  ][ 2018-03-01 15:27:06] -> 		0) type:vec3 name: vertex_position location: 0
[ INFO  ][ 2018-03-01 15:27:06] -> 		1) type:vec2 name: vt_loc location: 1
[ INFO  ][ 2018-03-01 15:27:06] -> 		GL_ACTIVE_UNIFORMS = 3:
[ INFO  ][ 2018-03-01 15:27:06] -> 		0) type:mat4 name: matrix location: 0
[ INFO  ][ 2018-03-01 15:27:06] -> 		1) type:vec4 name: vt_ location: 1
[ INFO  ][ 2018-03-01 15:27:06] -> 		2) type:sampler2D name: basic_texture location: 2
[ INFO  ][ 2018-03-01 15:27:06] -> ------------- end info ---------------
[ INFO  ][ 2018-03-01 15:27:06] -> program 9 GL_VALIDATE_STATUS = 1:
[ INFO  ][ 2018-03-01 15:27:06] -> ------------- shader programme 9 info ---------------
[ INFO  ][ 2018-03-01 15:27:06] -> 		GL_LINK_STATUS = 1:
[ INFO  ][ 2018-03-01 15:27:06] -> 		GL_ATTACHED_SHADERS = 2:
[ INFO  ][ 2018-03-01 15:27:06] -> 		GL_ACTIVE_ATTRIBUTES = 2:
[ INFO  ][ 2018-03-01 15:27:06] -> 		0) type:vec3 name: vertex_position location: 0
[ INFO  ][ 2018-03-01 15:27:06] -> 		1) type:vec2 name: vt_loc location: 1
[ INFO  ][ 2018-03-01 15:27:06] -> 		GL_ACTIVE_UNIFORMS = 4:
[ INFO  ][ 2018-03-01 15:27:06] -> 		0) type:mat4 name: matrix location: 0
[ INFO  ][ 2018-03-01 15:27:06] -> 		1) type:vec4 name: vt_ location: 1
[ INFO  ][ 2018-03-01 15:27:06] -> 		2) type:sampler2D name: basic_texture location: 2
[ INFO  ][ 2018-03-01 15:27:06] -> 		3) type:float name: alpha_factor location: 3
[ INFO  ][ 2018-03-01 15:27:06] -> ------------- end info ---------------
[ INFO  ][ 2018-03-01 15:27:06] -> 2D Graphics Engine start [OK]
[ INFO  ][ 2018-03-01 15:27:06] -> Graphics Engine started
[ INFO  ][ 2018-03-01 15:27:17] -> 

[ INFO  ][ 2018-03-01 15:27:17] -> deleting shader programe 3
[ INFO  ][ 2018-03-01 15:27:17] -> deleting shader programe 6
[ INFO  ][ 2018-03-01 15:27:17] -> deleting shader programe 9
[ INFO  ][ 2018-03-01 15:27:17] -> 2D Graphics  Engine closed [OK]
[ INFO  ][ 2018-03-01 15:27:17] -> Window closed [OK]
[ INFO  ][ 2018-03-01 15:27:17] -> Graphics Engine stopped [OK]
[ INFO  ][ 2018-03-01 15:27:17] -> Logger closed [OK]
[ INFO  ][ 2018-03-01 15:27:17] -> Game Engine stopped [OK]

What's next?

   I am learning about the type of game I am doing, I should have some basic movement of main character and platform collisions soon. I promise myself I will not do everything alone again so this blog will be also used to seduce whoever want to jump into this adventure. But by experience I know I may finish alone again (who knows).

Thanks for reading, I will post more as soon as I have something new to show.

Have a nice day.



5 Comments


Recommended Comments

Thanks, something will be finished this week-end (I hope)

Share this comment


Link to comment
On 3/2/2018 at 7:59 PM, lilington said:

Thanks, something will be finished this week-end (I hope)

How's the project coming along?

Share this comment


Link to comment

Hello,

Minimal input module (keyboard only by now) is finish.

gravity is finished, objet can jump and fall but no collision, so just fall down out of screen.

At this moment, I am trying to solve a deformation after rotation, looks like projection matrix is wrong somewhere.  I need to solve this before i continue to collisions.

Edited by lilington

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Advertisement
  • Blog Entries

  • Similar Content

    • By MiTi
      Dear everyone, this is my newest game, please check out and give me feedback. Thanks for your consideration.

      Overview: Cross n Puzz is a creative and addicting word puzzle game. It not only challenges your brain but also improve memory and other types of cognitive function.

      For IOS: https://itunes.apple.com/app/crossword-puzzle-image/id1435575074

      For Android: https://play.google.com/store/apps/details?id=com.caag.crosswordnpuzzle

      Game trailer: https://www.youtube.com/watch?v=stNuktpJH44&feature=youtu.be
      Crossword Puzzle Image Trailer Official.mp4  
    • By _Flame_
      Hello.
      I'm tring to implement opencl/opengl interop via clCreateFromGLTexture (texture sharing)
          glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
      With such texture I expected that write_imagei and write_imageui would work but they don't. Only write_imagef works. This behaviour is same for intel and nvidia gpus on my laptop. Why is it and why there is no such information in any documentation and in the entire internet? This pitfall cost me several hours and probably same for many developers.
       
       
    • By Hashbrown
      When importing sprites in Unity, we get a Pixels Per Unit option. The smaller the value, the larger it looks on screen. This is great for very small (50x32px) sprites I download.
      My question is, how can I accomplish this with OpenGL? Should I make the sprite larger in the frag shader? I don't want to scale the game object, I'd like the image to be rendered at the size I need without changing the scale, similar to Unity.
      No code needed, just some suggestions that put me in the right direction. Thanks!
    • By Michael Barth
      Hello there!
      So I want to understand this better. With OpenGL 4.6, support was added to be able to run SPIR-V compiled shaders. I've messed around with it, gotten it to work. It's a little bit more complicated to have to use UBOs for most things now. What I mainly want to know is what the benefits are. So I understand SPIR-V is bytecode, and that it's used by Vulkan and that because it's bytecode, there isn't any worry about wild inconsistencies across GPU vendors. When OpenGL is using SPIR-V, does it also benefit from this?
      Also, does this deal with micro-stutter that's caused by shaders being loaded for the first time using traditional GLSL and shader caching?
      I have some application that uses some really old version of GLSL, like GLSL 120, and I'd been thinking about updating it and properly supporting GLSL 460 compiled to SPIR-V. The application also uses DX9, so I was just curious how updating and using these new techniques with OpenGL 4.6 would stack up against the old GLSL or DX9 methods. I'm not expecting some magic performance benefit, I'm just legitimately curious if it'd be worth it to try.
    • By Lewa
      So, i'm currently in the process of implementing a reversed floating point depth buffer (to increase the depth precision) in OpenGL. I got everything working except the modifications to the projectionmatrices nessecary for this to work.
      (Matrices are my weakness.  )
      What i got working are a projectionMatrix and an orthographic projection matrix which has the x-y range spaning from -1 to 1 and the z range from 0-1 as in DirectX. (it's basically the exact same code from the glm library)
      I use them in combination with:
      glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE); Here are the two matrices:
      void Camera::setProjectionPerspektiveY_reverseDepth_ZO(float fovY, float width, float height, float znear, float zfar) { float rad = MathE::toRadians(fovY); float h = glm::cos(0.5f * rad) / glm::sin(0.5f * rad); float w = h * height / width; glm::mat4 p; p[0][0] = w; p[1][1] = h; p[2][2] = zfar / (znear - zfar); p[2][3] = -1; p[3][2] = -(zfar * znear) / (zfar - znear); this->projectionMatrix = p; } void Camera::setProjectionOrtho_reversed_ZO(float left, float bottom, float right, float top, float znear, float zfar) { glm::mat4 p; p[0][0] = 2.0f / (right - left); p[1][1] = 2.0f / (top - bottom); p[2][2] = -1.0f / (zfar - znear); p[3][0] = -(right + left) / (right - left); p[3][1] = -(top + bottom) / (top - bottom); p[3][2] = -znear / (zfar - znear); this->projectionMatrix = p; }  
      My question is: Does anybody know how to properly reverse the depth on both of these matrices? (from 0-1 to 1-0)
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!