Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 26 Nov 2012
Offline Last Active Jan 05 2016 02:31 PM

#5265106 How to send a CubeMap texture to a compute shader?

Posted by Solid_Spy on 06 December 2015 - 01:59 AM



I found the issue. At first I thought that GL_RGBA8 and GL_RGBA32F were equivalent, for some reason :P. I changed my textures to GL_RGBA32F and now it is officially working.

#5251989 Struggling with casting cloud shadow on earth sphere in OpenGL

Posted by Solid_Spy on 13 September 2015 - 01:31 AM

Try generating a new rotation matrix just for the cloud shadow. Do not use the same one, because it will add its rotation to the earths rotation matrix.


Generate the new rotation matrix by subtracting the clouds rotation by the earths rotation, and then create a rotation matrix out of those newly calculated rotations. Plug it into your shader, and that should fix the problem.

#5211797 OpenCL for both AMD and NVidia graphics cards with MinGW?

Posted by Solid_Spy on 19 February 2015 - 07:05 PM

I know it's not quite the same, but can't you use the GL_ARB_compute_shader? Assuming you have access to version 4.3.


You know what, Screw OpenCL.


I'm goin for OpenGL 4.3 compute shaders :P.

#5211760 What's a good general max fps for a 3d graphics engine?

Posted by Solid_Spy on 19 February 2015 - 03:39 PM

So when you say that you lost 200fps, you could mean that the function takes a fraction of a millisecond, or several seconds.

Add timers around blocks of CPU code, and timer events around large sections of draw calls, in order to measure how long different operations actually take.


Ah, Ok. I shall measure time in milliseconds for those functions from now on.

#5204863 Boost 1.5 with XML Why u no have ptree!?

Posted by Solid_Spy on 16 January 2015 - 10:08 PM

ptree is just a typedef of basic_ptree. It is defined in boost/property_tree/ptree_fwd.hpp (which is included by ptree.hpp)

I seriously don't know how I missed that :/.

#5204852 Looking for a good way to make games in C/C++ on linux for cross-platform

Posted by Solid_Spy on 16 January 2015 - 08:58 PM

Darn lol, I meant glfw. Idk how I made that typo. Too many effing GL acronyms :P.

#5203503 Looking for a good way to make games in C/C++ on linux for cross-platform

Posted by Solid_Spy on 11 January 2015 - 11:21 AM

If you want something more low level, I highly recommend glfw GLSL. Although you will need additional libraries for other features such as file searching, etc.

#5203324 Speeding up cpu side of rendering engine

Posted by Solid_Spy on 10 January 2015 - 02:26 PM

I didn't read i all, but if I understand correctly, you only need to set a vertexbuffer, texture and material once. And then just render all objects by just passing their world matrix and committing.

Do you really need the 12.000 objects to be individual objects?
If not, why not bundle them into a few objects and see how that goes, for example setting 1 world matrix to the shader instead of a couple of thousand might help you.

That is exactly what I am doing. I have a renderqueue system set up so that the vertexBuffer and materials get set only once. I only have around 20 matrices being set, not a couple thousand, because I am only rendering 4 objects, and if I am allowing rendering of a thousand objects, I use frustum culling.


I am not grouping objects, because I might want them to have individual collisionComponents, positionComponents, renderComponents... etc. I could try and cheat in some places by combining objects into one I guess, but it won't be very dynamic. Maybe I will do it for static objects with no collision.


Unfortunately, If I were making a tiled 3d dungeon crawler or a platform game, or even a bullet hell or zombie horde, I am going to need a couple thousand objects per level.

#5203310 Speeding up cpu side of rendering engine

Posted by Solid_Spy on 10 January 2015 - 12:48 PM

Nice, one step closer smile.png
This might mean that your challenge lies more on the GPU side

Well the thing is, I have over 15000 game objects in my scene, and I am only rendering 2 of them. They are all the same object.


My objects only have 1 mesh and 1 material tongue.png.


I have a feeling it is my use of shared_ptrs and weak_ptrs that are slowing this down, because I cannot think of anything else to speed this up.


Here is my updated code:

void RenderingEngine::frustumCulling()
	std::shared_ptr<PositionComponent> curPosComp = mainCamera->GetPositionComponent();
	glm::vec3 axisPoint = glm::vec3(

	glm::vec3 planeNearDirec = glm::normalize(curPosComp->GetDirection());
	glm::vec3 planeFarDirec = -glm::normalize(curPosComp->GetDirection());
	glm::vec3 planeLeftDirec = glm::vec3(cos(curPosComp->GetRotationY()+0.77f),
	glm::vec3 planeRightDirec = glm::vec3(cos(curPosComp->GetRotationY()-0.77f),

	glm::mat4 rotationMatY = glm::rotate(glm::mat4(1.0f),
			(curPosComp->GetRotationY() * (180 / 3.14159f)),
			glm::vec3(0.0f, 1.0f, 0.0f));

	glm::mat4 rotationMatZ = glm::rotate(glm::mat4(1.0f),
			glm::vec3(0.0f, 0.0f, 1.0f));

	glm::mat4 rotationMatFinal;

	glm::vec4 tempPlaneTopDirec = glm::vec4(1.0f, 0.0f, 0.0f, 0.0f);

	rotationMatFinal = rotationMatY * rotationMatZ;

	tempPlaneTopDirec = rotationMatFinal * tempPlaneTopDirec;

	glm::vec3 planeTopDirec = glm::vec3(tempPlaneTopDirec.x,

	glm::vec3 planeDownDirec;

	glm::vec3 toNearPlaneDirec = axisPoint + (planeNearDirec * mainCamera->GetNear());
	glm::vec3 toFarPlaneDirec = axisPoint + (planeNearDirec * mainCamera->GetFar());

	glm::vec3 posCompAxisPoint = glm::vec3(1.0f);

	float dotProduct[6];

	std::weak_ptr<RenderingComponent> currentWeakRenComp;
	std::shared_ptr<RenderingComponent> currentRenComp;
	for(unsigned int i = 0; i < renderingComponents->size(); i++)
		currentWeakRenComp = renderingComponents->at(i);
			currentRenComp = currentWeakRenComp.lock();
			std::shared_ptr<PositionComponent> curRenPosComp = currentRenComp->GetPositionComponent();
			posCompAxisPoint = glm::vec3(curRenPosComp->GetPositionX(),
			glm::vec3 finalVec1 = posCompAxisPoint - toNearPlaneDirec;
			glm::vec3 finalVec2 = posCompAxisPoint - toFarPlaneDirec;
			glm::vec3 finalVec3 = posCompAxisPoint - axisPoint;
			dotProduct[0] = glm::dot(finalVec1, planeNearDirec);
			dotProduct[1] = glm::dot(finalVec2, planeFarDirec);
			dotProduct[2] = glm::dot(finalVec3, planeLeftDirec);
			dotProduct[3] = glm::dot(finalVec3, planeRightDirec);
			dotProduct[4] = glm::dot(finalVec3, planeTopDirec);
			if(dotProduct[0] >= 0 &&
			   dotProduct[1] >= 0 &&
			   dotProduct[2] >= 0 &&
			   dotProduct[3] >= 0 &&
			   dotProduct[4] >= 0)
			renderingComponents->erase(renderingComponents->begin() + i);

void RenderingEngine::StartRender()
	glClearColor(0.2f, 0.4f, 0.6f, 1.0f);



void RenderingEngine::RenderObjects()
	GLuint location;

	//Get the main camera:
	for(unsigned int i = 0; i < cameras->size(); i++)
		std::shared_ptr<CameraComponent> cameraComponent =
		if(cameraComponent->GetCameraName() == "mainCamera")
			mainCamera = cameraComponent;

	//Frustum culling:


	//Update the render queues.

	std::shared_ptr<RenderingComponent> currentRenderComponent;
	for(unsigned int i = 0; i < renderingComponents->size(); i++)
		currentRenderComponent = renderingComponents->at(i).lock();
		if(currentRenderComponent->GetActive() == true)
			std::shared_ptr<Mesh> currentMesh = currentRenderComponent->GetMesh();
			attribVector * currentAttribBuffers = currentMesh->GetAttributeBuffers();
			materialVector * currentMaterials = currentMesh->GetMaterialVector();

			for(unsigned int j = 0; j < currentAttribBuffers->size(); j++)
				std::shared_ptr<AttributeBuffer> currentAttrib = currentAttribBuffers->at(j);
				std::shared_ptr<Material> currentMaterial;
				for(unsigned int k = 0; k < currentMaterials->size(); k++)
					if(currentMaterials->at(k)->GetMaterialName() == currentAttrib->materialName)
						currentMaterial = currentMaterials->at(k);
				RenderQueueNode renderQueueNode;
				renderQueueNode.attribute = currentAttrib;
				renderQueueNode.renderingComponent = currentRenderComponent;
				renderQueueNode.material = currentMaterial;
				renderQueueNode.blendType = currentMaterial->GetBlending();
				renderQueueNode.shaderIndex = currentMaterial->GetShaderIndex();
				renderQueueNode.distanceFromCamera = 0;
				renderQueueNode.frameBuffer = 0;

				if(renderQueueNode.blendType == SOLID_BLEND_NORMAL)


	//Render main objects:
	//Render the sub meshes in the render queues:


What would you recommend that I do to speed things up?

#5202895 Speeding up cpu side of rendering engine

Posted by Solid_Spy on 08 January 2015 - 01:24 PM


Ok, so I tried a release build instead this time.


Doing a release build made everything run much faster, but lags a little still.

#5202879 Speeding up cpu side of rendering engine

Posted by Solid_Spy on 08 January 2015 - 12:15 PM

I've been having problems on the cpu side of things while getting a rendering engine to work.
The rendering works fine, and i've been using instance rendering, but it seems like the more objects I add, the slower it gets. I want to render at least 2000 different objects to the screen. the 3d models are low poly. I've limited the number of objects that get rendered, but even still, the program slows down significantly if I add more objects to the program.
I do NOT want to use multithreading for this solution. I also do not want to use frustum culling just yet, because I want ALL the objects to be rendered and be visible. I just want a way to speed up my rendering engine on the cpu side. In order for me to render my objects, I have to iterate through a list of objects, check if it has a rendering component, check it's material for a matching shader... etc.
I have a feeling all of these iterations and searching through maps with strings are causing problems, but I don't know any better solution to fixing this. I have ideas, but i'm not sure if they are the best solutions. I was thinking of using a fixed size array of rendering components, but that may be too limiting. I'm just not sure what to do :/
I was wondering if anyone can review my code and tell me how to speed things up significantly.
Apparently the forum won't let me post with code tags tongue.png, so here are some pieces of code I am using, and these are the sections I think are causing the most lag:

#include <glew.h>
#include <glfw3.h>
#include <windows.h>
#include <string>
#include <vector>
#include <memory>
#include <map>
#include <ft2Build.h>
#include FT_FREETYPE_H

#include "TextBox.h"
#include "Mesh.h"
#include "Shader.h"
#include "Mesh.h"
#include "GameObject.h"
#include "TextComponent.h"
#include "RenderingComponent.h"
#include "CameraComponent.h"

struct instanceRenderingData
    bool active;
    unsigned int numOfInstances;
    GLuint streamedPositionBuffer;
    //Remember to delete!
    std::shared_ptr<RenderingComponent> * renderingComponents;

typedef std::map<std::string, instanceRenderingData> instanceRenderDataMap;
typedef std::pair<std::string, instanceRenderingData> instanceRenderDataMapPair;
typedef std::vector<std::shared_ptr<GameObject>> gameObjectPtrVector;
typedef std::map<std::string, std::shared_ptr<Mesh>> meshSPtrMap;
typedef std::map<std::string, std::shared_ptr<Texture>> textureMap;
typedef std::map<std::string, FT_Face> fontMap;

// Class: RenderingEngine
// This is the primary class for managing all the rendering in the game.
// It allows you to render 3d models, as well as perform special effects
// and draw text.
// This class has a system in place, in which it renders things in a
// specific order:
// 1. Clear the main buffer.
// 2. Render all of the shadow maps for all of the lights.
// 3. Draw all of the opaque objects to a separate buffer.
// 4. Draw all of the objects with alpha clipping to the same buffer.
// 5. Draw all of the opaque objects with additive blending to the same
//    buffer.
// 6. Draw all of the alpha objects to the same buffer.
// 7. Use special effects on a separate buffer. Ping pong if necessary.
// 8. Render the text on the same buffer.
// 9. Swap the buffers.
// Everything will be rendered to a buffer the size that is specified in
// the cfg file, which is read by the fileLoader class.
class RenderingEngine {
    virtual ~RenderingEngine();



    // Method: InitializeRenderingEngine
    // Initializes the rendering engine, and sets up openGL.
    // It also loads all of the shaders for use.
    void InitializeRenderingEngine();

    // Method: RenderMesh
    // Renders a single mesh, based on its material and shader. Usually
    // called by the loop render method.
    void RenderMesh(std::shared_ptr<RenderingComponent> renderingComponent,
            std::shared_ptr<Material> currentMaterial);

    void RenderInstanced(instanceRenderingData& instRendData,
            std::shared_ptr<Material> currentMaterial);

    // Method: RenderTextBox
    // Renders a text box to the final back buffer. Usually done near the
    // end of rendering.
    void RenderTextBox(std::shared_ptr<TextComponent> textComponent);

    // Method: LoopRender
    // This method specifically loops through all of the game objects and
    // checks if it has a rendering component. If it does, it checks its
    // material and checks if it has the proper shader and blend function.
    // If it does, then it calls the RenderMesh method.
    void LoopRender(Shader& shader);

    // Method: StartRender
    // Starts the rendering process, by clearing the back buffer.
    void StartRender();

    // Method: RenderObjects
    // VERY IMPORTANT! The main method for rendering all of the objects to
    // the screen. This is the update function of the Rendering engine, and
    // is called inside of the game loop.
    void RenderObjects();

    // Method: EndRender
    // Ends the rendering by swapping the buffers.
    void EndRender();
    void AddMesh(std::shared_ptr<Mesh> mesh);

    // Method: AddMesh
    // Adds a mesh to the rendering engine.
    std::shared_ptr<Mesh> FindMesh(std::string meshName);



    void SetCurrentWindow(GLFWwindow * sGlfwWindow);
    void SetShader(shaderIndexEnum shaderIndex, Shader sShader);
    void SetObjectPtrVector(gameObjectPtrVector * sGameObjectPtrVector);



    gameObjectPtrVector * GetCameras();
    Shader GetShader(shaderIndexEnum shaderIndex);
    materialMap * GetMaterials();
    meshSPtrMap * GetMeshes();

    GLFWwindow * currentWindow;

    GLuint letterTexture;
    GLuint quadVertexArray;
    GLuint quadVertexBuffer;
    GLuint quadUVBuffer;
    GLuint quadIndiceBuffer;

    glm::mat4 viewMatrix;
    glm::mat4 projectionMatrix;

    gameObjectPtrVector * gameObjects;
    gameObjectPtrVector * cameras;
    meshSPtrMap * meshes;
    materialMap * materials;
    fontMap fonts;
    instanceRenderDataMap instanceRenderDataPackets;

    std::shared_ptr<CameraComponent> mainCamera;

    //Shader programs:
    // Light: lighting, with specular
    // Shad: shadow maps (up to 8)
    // Refl: cube map reflection
    // Anim: has 3d bone animation
    // #D: num of diffuse maps (up to 4)
    // #N: num of normal maps (up to 4)
    // #S: num of normal maps (up to 4)
    Shader testShader;
    Shader testShaderInst;
    Shader shaderCheap1D;

    Shader shaderText1D;

    Shader shaderLight1D;

void RenderingEngine::RenderObjects()
    GLuint location;

    //Update all of the instanced render buffers:
    for(unsigned int i = 0; i < gameObjects->size(); i++)
        componentMap currentComponentMap =
        if(currentComponentMap.find(1) != currentComponentMap.end())
            std::shared_ptr<RenderingComponent> currentRenderingComponent =
            materialMap * currentMaterialMap =
            for(matMapIterator j = currentMaterialMap->begin();
                    j != currentMaterialMap->end();
                if(j->second->GetInstanceRendered() == true)
                    if(instanceRenderDataPackets.find(j->second->GetMaterialName()) ==
                        MessageBox(0, "yes", "m", MB_OK);
                        instanceRenderingData instRendData;
                        instRendData.active = true;
                        instRendData.numOfInstances = 1;
                        instRendData.renderingComponents = new std::shared_ptr<RenderingComponent>[1024];
                        instRendData.renderingComponents[0] = currentRenderingComponent;
                        glGenBuffers(1, &instRendData.streamedPositionBuffer);

                        glBindBuffer(GL_ARRAY_BUFFER, instRendData.streamedPositionBuffer);
                        glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 16 * 1024, NULL, GL_STREAM_DRAW);
                                        j->second->GetMaterialName(), instRendData));
                        //MessageBox(0, "add", "m", MB_OK);
                        instanceRenderingData * currentInstRendData =
                        if(currentInstRendData->numOfInstances < 1024)
                            currentInstRendData->active = true;
                            currentInstRendData->numOfInstances += 1;
                            currentInstRendData->renderingComponents[currentInstRendData->numOfInstances - 1] =

    //Get the main camera:
    for(unsigned int i = 0; i < cameras->size(); i++)
        std::shared_ptr<CameraComponent> cameraComponent =
        if(cameraComponent->GetCameraName() == "mainCamera")
            mainCamera = cameraComponent;

    //Render main objects:
    //First, render the instanced objects:

    for(instanceRenderDataMap::iterator i = instanceRenderDataPackets.begin();
            i != instanceRenderDataPackets.end();
        if(i->second.numOfInstances > 0)
            RenderInstanced(i->second, materials->find(i->first)->second);

    //Then, render the opaque objects:


    //Render text:

    for(unsigned int i = 0; i < gameObjects->size(); i++)
        componentMap currentComponentMap = gameObjects->at(i)->GetComponentMap();
        if(currentComponentMap.find(4) != currentComponentMap.end())
            std::shared_ptr<TextComponent> textComponent =


void RenderingEngine::LoopRender(Shader& shader)
    std::shared_ptr<RenderingComponent> currentRenderingComponent;
    for(unsigned int i = 0; i < gameObjects->size(); i++)
        componentMap currentComponentMap = gameObjects->at(i)->GetComponentMap();
        if(currentComponentMap.find(1) != currentComponentMap.end())
            currentRenderingComponent = std::static_pointer_cast<RenderingComponent>(
            std::shared_ptr<Mesh> currentMesh = currentRenderingComponent->GetMesh();
            std::vector<AttributeBuffer> * currentAttribBuffers = currentMesh->GetAttributeBuffers();
            materialMap * currentMaterials = currentMesh->GetMaterialMap();

            for(unsigned int j = 0; j < currentAttribBuffers->size(); j++)
                AttributeBuffer currentAttrib = currentAttribBuffers->at(j);
                std::shared_ptr<Material> currentMaterial;
                currentMaterial = currentMaterials->find(currentAttrib.materialName)->second;
                if(currentMaterial->GetShaderIndex() == shader.GetShaderIndex())

#5198617 How to compile libraries for C++ MinGW with MSYS on Windows - for indie game...

Posted by Solid_Spy on 16 December 2014 - 03:28 PM

Compiling libraries is something that a lot of indie game developers have trouble with, especially if they are using Eclipse or CodeBlocks with MinGW. Compiling libraries is just one of those things that people just assume you know how to do, although it doesn't seem like there is all that much information, (or information that is clear) on how to properly build libraries. They never even taught me how to do it in college tongue.png.

I am specifically going to teach you how to compile libraries for your indie game using MSYS and MinGW. I am going to use glew32 as an example, since that is a very popular library, especially for those working with OpenGL.

I will explain step by step how to compile the libraries.

Step 1: Download MinGW and MSYS. They should be on the main website, and shouldn't be too hard to find. MSYS will usually be downloaded along with MinGW.

Step 2: Make sure you downloaded MinGW to your C:\ directory, and that msys is inside of the folder.



Step 3: Add the folders C:\MinGW\bin and C:\MinGW\mingw32\bin to your PATH: variables. VERY IMPORTANT, I'm guessing a lot of people skip this step by accident. You can find the path variables by going into search, and typing "path variables". You need these in your path variables so that way cmd.exe has global access to the programs inside of these folders, without having to change directories.

Step 4: Download the Glew32... tsk... "libraries", off of the glew website.

Step 5: Open cmd.exe

Step 6: type: cd, and a space after it and then copy/paste the file directory to the Glew folder that has a MakeFile in it. into the cmd.exe window.

Step 7: press enter, and then type bash, and then press enter again. now you should see a dollar sign appear in the cmd window. If you do not see a dollar sign, then chances are that you didn't properly add MinGW\bin or MSYS\bin to your PATH variable.

Step 8: type mingw32-make, and then press enter. Now it should lag a little, but if you wait a while, you should see a lot of weird, err, stuff appear in the window. That's ok, that's normal. That means you did it right!. Now if you wait a while, you should see bash appear at the bottom with the dollar sign again, and it should look something like this.



Step 9: you have just compiled your libraries! Great! ...where are they? Well if you look inside of the lib folder of your glew32 folder, you should see a bunch of new stuff there that wasn't there before. You should see a libglew32.a and a glew32.dll. Now Those are the important ones! The .a one is the static library, and the .dll is the dynamic one.



Step 10: If you wish to use these libraries, i suggest putting them into different folders so that your ide has an easier time finding them. For example, Eclipse will sometimes confuse libglew32.a with libglew32.dll.a.

And that's it!

Now, there are a few gotcha's:


Make sure everything you are downloading is of the same bit amount, for example, make sure everything is 32-bit. And I mean, EVERYTHING! Including your program, and your other libraries.

Not all libraries you download off of the internet will have a makefile, and not all makefiles require the same procedures as simply typing mingw32-make. For example, the Freetype library, also a very popular library for game development, requires that you type ./configure first, before typing mingw32-make. It is VERY important to read the read me file of any library you download, as they may provide valuable information.

As for the libraries that do not have makefiles, for example, the boost libraries, which have .jam files instead. You will need a different compiler program sadly. There are many different compiler programs that are beyond the scope of this tutorial i'm afraid, however I am sure there are video tutorials that can teach you how to use them.

And that's it, that's how you compile libraries with MinGW and MSYS for C++. Thank you for reading my tutorial ^^.

#5198054 Cannot get freetype to render glyph to texture

Posted by Solid_Spy on 13 December 2014 - 06:24 PM

Not at all smile.png someone should probably update the wiki tongue.png

I just did lel.

#5167532 Need advice for developing a game?

Posted by Solid_Spy on 18 July 2014 - 01:19 AM

You may also want to learn how to make computer programming, so that you can create much computer..


But joking aside, if you are looking for a computer language to start out with, I would highly reccomend that you start out with c#, since it is a very easy language to learn at first, and is used by Unity. I would also reccommend c++, however it is a fairly advanced language, and wouldn't get you very close to creating your first game, but it would help you in learning how to create games using more advanced engines, or writing your own engine, in the future. It is also the language that most people start out with, since it makes it easier to learn other languages due to it's difficulty.


If you want my story, I started out with GameMaker, since it used drag and drop, and didn't need that much coding. I got to learn a lot of gaming fundamentals, and learned a lot of algorithms. I later moved on to Flash, then learned c++, then learned c#, etc...

#5150694 Gl Bind Texture is taking over my program X(!

Posted by Solid_Spy on 30 April 2014 - 11:44 PM

Update: I fixed the problem.


It had NOTHING to do with the bind texture. I had a parameter in my shader compiler that always loaded the texture pixel shader, making the color shader use the texture pixel shader.