[Java] My Game Engine: The beginning

Accname

2D-Graphics enthusiast
Reaction score
1,462
Starzi Engine
What is this about:​
This is my own 2D game engine based on OpenGL (LWJGL).
I am working on this now for over a year and I want to create my games using this engine in the future.
I want to show some of the functionality here and maybe get some feedback on my work.
 

Cat

New Member
Reaction score
2
What does this produce? I'm a bit lost when it comes to "engines," etc.
 

Sevion

The DIY Ninja
Reaction score
413
What does this produce? I'm a bit lost when it comes to "engines," etc.

Engines produce nothing by themselves. They are a framework to build something else.

E.G. Source Engine was the framework for games like Team Fortress 2. By itself, Source Engine does absolutely nothing. There is no "start" or "main" function or method in the Source Engine code. That code is written by a programmer using the Source Engine in order to make a game like Team Fortress 2.
 

monoVertex

I'm back!
Reaction score
460
An engine has built-in facilities that allow a programmer to be concerned about more high-level decisions in his program, instead of implementing low-level tasks. Basically, it allows you to create a more complex application in a shorter time.

And the difference between the facilities implemented in an engine and the same facilities implemented directly in the program is that the engine has some kind of API, an interface, which allows different programmers to use the same framework / engine, without requiring modifications to the internal code.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
Loading Textures
This step of the Guide will show you how to load textures with my engine.
The engine has a simple Texture class. Each instance of this class represents a unique texture on your video card.
To create a texture you can use its Constructor; it takes only one parameter, the textures type.
The type of a texture is constant, after you have set it in the constructor it will never change again.
The texture type is an enum. Null is not an accepted argument.
Code:
            texture = new Texture(Type._2D);
Other types include: _1D, _1D_ARRAY, _2D_ARRAY, _3D, etc.
At this point in time our texture does not yet have any images, and thus no texels. You can not render with this texture yet.
Before you change the state of a texture you need to bind it. Only one texture can be bound to a texture unit at one point in time, but there are several different texture units you can choose from.
The max number of texture units is limited by your graphics card.
You can also omit the parameter in the bind method, in this case the default texture unit (0) will be used.
Code:
            /*
            * Binds the texture to the Texture-Image-Unit 2 (if it is available).
            * If your graphics card does not support 3 or more Texture-Image-Unit's this method will throw an exception.
            */
            texture.bind(ImageUnit.get(2));
     
            /*
            * Alternatively: This will bind the texture to the last Texture-Image-Unit that this texture was previously bound to.
            * After a texture has been constructed this will default to Texture-Image-Unit 0.
            */
            texture.bind();
Now we need to set the number of levels that our texture is going to have.
Each level represents an Image in the texture. The base level is the original image, the following images are usually the mipmaps of the texture.
The method set_levels takes 2 parameters, the base level for the texture (is usually 0) and the max level. The max level can also be 0, in this case the texture will not have any mipmaps.
Code:
            /*
            * baseLevel and maxLevel are equal
            * => texture has exactly 1 image
            */
            texture.set_levels(0, 0);
     
            /*
            * texture has 6 images; the base image and 5 mipmaps.
            */
            texture.set_levels(0, 5);
     
            /*
            * texture will calculate a recommended level count based on the size of the base level image.
            * The returned value can be used for the maxLevel.
            * When constructing mipmaps this number of levels will be enough to
            * leave the lowest mipmap with a size of 1x1x1.
            */
            texture.set_levels(0, texture.get_recommendedLevelCount(256, 256, 1));
Now we can start to fill our textures with images. After you have set the images they are still empty and do not contain any texel data yet.
To fill our texture with texels we use the class Texels.
Code:
            Texels texels = null;
            try {
                texels = Texels.image2D("Assets/SomeTexture.png");
            } catch (IOException e) {
                e.printStackTrace();
            }
This code will load a .png image from disk and use it to generate a texels for our texture.
You can also load image files as 1D and 3D texels.
An alternative way is to create the texels yourself by using an array of floats:
Code:
            Texels texels = Texels.image(4, 4, 1, new float[] {
                    1, 0, 0, 1,
                    1, 0, 0, 1,
                    1, 0, 0, 1,
                    1, 0, 0, 1,
               
                    0, 1, 0, 1,
                    0, 1, 0, 1,
                    0, 1, 0, 1,
                    0, 1, 0, 1,
               
                    0, 0, 1, 1,
                    0, 0, 1, 1,
                    0, 0, 1, 1,
                    0, 0, 1, 1,
               
                    1, 0, 1, 1,
                    1, 0, 1, 1,
                    1, 0, 1, 1,
                    1, 0, 1, 1,
            }, TexelFormat.RGBA);
This would create two-dimensional texel data with 4x4 texels. The first row of our generated image would be red texels, the next row is green texels, the next row is blue texelsand the last row is purple texels.
At the end we upload our texels to an image of the texture:
Code:
            texture.get_image(0).put_texels(texels);
The parameter to get_image takes the level of the image. Be aware that if you have set the baseLevel of your texture to something other then 0 you have to use this very same value to access the base image.

You can use this same code to upload texel data for each level of your texture. Or, if you just want quickly generated mipmaps you can use the build in generate_mipmaps method:
Code:
            texture.generate_mipmaps(GLHint.NICEST);


The texture class has many other useful methods to change its state. Many of these are wrapped around enum's to guarantee simple and intelligible code.

Here is a small example method setting up a texture, generating its mipmaps automatically and then saving each mipmap and the base level to disk:
Code:
        public void loadTexture() {
            Texels texels = null;
            try {
                texels = Texels.image2D("Assets/Tex.png");
            } catch (IOException e) {
                e.printStackTrace();
            }
 
            texture = new Texture(Type._2D);
            texture.bind();
            texture.set_levels(0, texture.get_recommendedLevelCount(128, 128, 1) - 1);
            texture.set_minFilter(MinFilter.NEAREST_MIPMAP_LINEAR);
            texture.set_magFilter(MagFilter.NEAREST);
            texture.set_wrap_s(Wrap.REPEAT);
            texture.set_wrap_t(Wrap.REPEAT);
            texture.set_wrap_r(Wrap.REPEAT);
            Image img = texture.get_image(0);
            img.put_texels(texels);
 
            texture.generate_mipmaps(GLHint.NICEST);
            for (int i = texture.get_baseLevel(); i <= texture.get_maxLevel(); i++) {
                System.out.println(texture.get_image(i));
                try {
                    texture.get_image(i).saveToDisk("T"+i, Filter.NONE, Compression.MAX);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
 
    }

Now with attached source code for all important classes. Please note that the code is not yet final and some functionality is still commented out.
(Or maybe not because the forum will not let me upload a .zip file)
 

Attachments

  • texturesSrc.zip
    11.9 KB · Views: 412

tom_mai78101

The Helper Connoisseur / Ex-MineCraft Host
Staff member
Reaction score
1,667
(Or maybe not because the forum will not let me upload a .zip file)

Now that's just weird. I've been uploading plenty of ZIP files from my end in my project threads. Or maybe the size of the ZIP file is too large.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
Now that's just weird. I've been uploading plenty of ZIP files from my end in my project threads. Or maybe the size of the ZIP file is too large.
Worked now, maybe the forum was just too wonky yesterday.
 

rover2341

Is riding a roller coaster...Wee!
Reaction score
113
pretty cool. Not sure how interested i would be in making a engine my self, but man that sounds pretty impressive.

I built my self a interface to tie into different engines. but its slows things down a bit, and adds another layer. that way I was able to move stuff from xna to unity in just over a day. (at least all the 2d, 3d, rendering).
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top