[Java] My Game Engine: The beginning

Accname

2D-Graphics enthusiast
Reaction score
1,464
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.
 
What does this produce? I'm a bit lost when it comes to "engines," etc.
 
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.
 
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.
 
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: 453
(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.
 
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.
 
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:
    I would be there for days, even with my camera set up slides can take a long time, and if they want perfect captures I really need to use my scanners that are professionally made for that. My camera rig works well for what it is, but for enlargements and things it's not as good.
  • Varine Varine:
    I've only had a couple clients with that so far, though. I don't have a website or anything yet though.
  • Varine Varine:
    Console repair can be worthwhile, but it's also not a thing I can do at scale in my house. I just don't have room for the equipment. I need an office that I can segregate out for archival and then electronic restoration.
  • Varine Varine:
    But in order for that to be real, I need more time, and for more time I need to work less, and to work less I need a different job, and for a different job I need more money to fall back on so that I can make enough to just pay like, rent and utilities and use my savings to find these projects
    +1
  • Varine Varine:
    Another couple years. I just need to take it slow and it'll get there.
  • jonas jonas:
    any chance to get that stolen money back?
  • jonas jonas:
    Maybe you can do console repair just as a side thing, especially if there's so much competition business might be slow. Or do you need a lot of special equipment for that?
  • jonas jonas:
    I recently bought a used sauna and the preowner told me some component is broken, I took a look and it was just a burnt fuse, really cheap to fix. I was real proud of my self since I usually have two left hands for this kinda stuff :p
  • tom_mai78101 tom_mai78101:
    I am still playing Shapez 2. What an awful thing to happen, Varine, and hopefully everything has been sorted out soon. Always use multi-factor authentication whenever you have the opportunity to do so.
    +1
  • Varine Varine:
    I think all of the money is accounted for now, and all the cards have been changed out, so I think for the most part it's taken care of now. Just need to go through and make sure all of my accounts are secured again, it's just time consuming.
  • Varine Varine:
    And yeah everything has 2 factor turned on now, or at least everything I can think of at the moment.
  • Varine Varine:
    The consoles don't need too much equipment that I don't already have. I would like to get a reflow oven, but I don't really want to buy one so I'm thinking about modifying a toaster oven I have to make something that will work for what I'm doing.
  • Varine Varine:
    I have the soldering irons and reflow and all that, but without an oven it's kind of hard to build mod chips and things like that. I made a handful of them with a hot air station, but it's a pain.
  • Varine Varine:
    The only thing I'm not really set up for is BGA rework. I've done it before a little bit, but not reliably, and that equipment is wildly expensive. You need X-rays and shit.
  • Varine Varine:
    I also have a couple 3D printers. I'm not super good with those and need to get an enclosure built, but they'll be useful for some aesthetic mods I've been thinking about. At least I can use them to do designs and then just have someone else print out the parts for me once I know they work.
  • Varine Varine:
    I also use them to make adapters for all my camera shit, but that's also an on the side thing for now. Lens adapters get really expensive.
  • Varine Varine:
    I've been trying to do some little art pieces as well, but I'm not much an engineer so they haven't gone great. I got some new things showing up to try and play with
  • Varine Varine:
    I want to build this tesserect kind of thing with mirrors, and I've been trying to make this like black hole diorama. In my head it looks really cool, but I kind of thought I could form polarizing lenses into a sphere but I tend to just destroy them every time I try.
  • Varine Varine:
    So I got a new idea, but I'm not sure how to make it work like I want without being able to get a polarizer curved. I think they are made out of PVA typically, and I thought I could just heat it up a little bit to soften the film, but that clearly isn't working. So I'm going to try a few other things, I'm thinking if I put a mirror film over the polarizing film I might get something cool. I have some polarized LED's as well, and I think if I make a central light source I can use the mirrors combined with the polarizers to make that central light APPEAR black. I have next week off so I'm going to spend some time trying to figure it out
  • Varine Varine:
    The tesserect works, at least. I just need to figure out how to be able to assemble it, but I think I have a pretty good idea of how to go about it. Or at least a prototype of it. I'll post some pictures next week
  • jonas jonas:
    That last bit sounds like the last entry in a scientist's journal in a destroyed research facility in a post-apocalyptic video game
  • Varine Varine:
    lol it's not that exciting
  • Varine Varine:
    Shiny tho
  • Varine Varine:
    Basically it's a cube with a two way mirror on the inside, and then a smaller cube suspended in that with a mirrors on the outside of it. Kind of like those infinity pictures where they use two mirrors to go forever. Only it's twelve mirrors
  • Varine Varine:
    And the tiniest LED strip I could find

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top