Пример #1
0
bool Window::init(int width, int height, char* title /* =  DEFAULT_TITLE*/)
{
	if (isInitialized())
	{
		Debug_Log("Window is already initialized.");
		return false;
	}

	m_width = width;
	m_height = height;
	m_title = title;

	m_window = glfwCreateWindow(m_width, m_height, m_title, nullptr, nullptr);

	if (isInitialized())
	{
		glfwMakeContextCurrent(m_window); ///< set the current window to have context
		Debug_Log("Window " << m_title << " has been initialized.");
		m_fpsCounter.start();
		return true;
	}

	else
	{
		Debug_Log("Window " << m_title << " has failed to initialize.");
		glfwTerminate();
		return false;
	}

	
}
Пример #2
0
void Scene::_OnStart()
{
    GameObject::_OnStart();

    if (!IsEditorGameObject())
    {
        List<Camera*> cameras = GetComponentsInChildren<Camera>();
        Debug_Log("Cameras: " << cameras);
        if (!cameras.Empty())
        {
            Camera *cam = cameras.Front();
            SetCamera(cam);
            Debug_Log("Found camera: " << cam);
        }
        else // Create default camera
        {
            Debug_Log("Creating default camera");
            GameObject *m_defaultCamera = new GameObject("DefaultCamera");
            m_defaultCamera->transform->SetPosition(Vector3(90));
            m_defaultCamera->transform->LookAt(Vector3::Zero);
            m_defaultCamera->SetParent(this);

            Camera *cam = m_defaultCamera->AddComponent<Camera>();
            cam->SetFovDegrees(60.0f); cam->SetZNear(0.1f);
            cam->SetZFar(99999.0f);
            SetCamera(cam);
        }
    }
}
Пример #3
0
void BuildGameThread::run()
{
    bool ok = false;
    String output = "";
    String cmd = "";
    cmd += "uic Assets/Engine/EditorWindow.ui > src/View/EditorWindowAutoGenerated.h";
    cmd += " && qmake \"BUILD_MODE=GAME\" && make -j8";

    SystemUtils::System(cmd.ToCString(), &output, &ok);

    if (!ok)
    {
        Debug_Error(output);
    }
    else
    {
        Debug_Log("Game has been built!");
    }

    if (ok && runGameAfterBuild)
    {
        String output = "";
        Debug_Log("Running Game...");
        SystemUtils::SystemBackground("./Game.exe");
        Debug_Log("Game is running!");
    }
}
Пример #4
0
void GLProgram::loadShaders(const char* vertexPath, const char* fragmentPath)
{
	m_programID = m_shaders.LoadShaders(vertexPath, fragmentPath); // load the shaders
	if (m_programID)
	{
		Debug_Log("The program id is " << m_programID); // check if the programid isnt 0.
		return;
	}
	Debug_Log("the program failed to load the shaders."); // Log that the program failed to load the shaders.
}
Пример #5
0
void GameBuilder::BuildGame(const String &absoluteDir, bool runGame)
{
    if (GameBuilder::buildThread.isRunning())
    {
        Debug_Log("Game is already being built");
    }
    else
    {
        GameBuilder::buildThread.runGameAfterBuild = runGame;
        GameBuilder::buildThread.start();
    }
}
Пример #6
0
void GameObject::SetParent(GameObject *newParent, bool keepWorldTransform)
{
    if (keepWorldTransform)
        Debug_Log("Set parent of " << this << " to " << newParent);

    if (m_parent != newParent)
    {
        if (m_parent)
        {
            m_parent->m_children.Remove(this);
        }

        if (keepWorldTransform)
        {
            // TODO: Not working yet (sometimes scaling breaks)

            Matrix4 oldParentToWorld;
            parent->transform->GetLocalToWorldMatrix(&oldParentToWorld);
            //Debug_Log("LOCAL TO WORLD: " << Transform::FromTransformMatrix(oldParentToWorld));

            Matrix4 worldToNewParent;
            if (newParent)
            {
                newParent->transform->GetLocalToWorldMatrix(&worldToNewParent);
                worldToNewParent = worldToNewParent.Inversed();
                //Debug_Log("WORLD TO NEW PARENT: " << Transform::FromTransformMatrix(worldToNewParent));
            }

            Matrix4 keepWorldTransformMatrix =
                    worldToNewParent * oldParentToWorld * transform->GetLocalToParentMatrix();
            //Debug_Log("LOCALTOPARENT: " <<
            //          Quaternion::EulerAngles(
            //              Transform::GetRotationFromMatrix4(transform->GetLocalToParentMatrix())));
            //Debug_Log("KEEPWORLDMATRIX: " << Transform::FromTransformMatrix(keepWorldTransformMatrix));

            Transform t = Transform::FromTransformMatrix(keepWorldTransformMatrix);
            transform->SetLocalPosition(t.GetLocalPosition());
            transform->SetLocalRotation(t.GetLocalRotation());
            transform->SetLocalScale   (t.GetLocalScale());
        }

        m_parent = newParent;

        if (m_parent)
        {
            m_parent->m_children.PushBack(this);
        }
    }
}
Пример #7
0
Window::Window(int width, int height, char* title) : 
m_width(width),
m_height(height),
m_title(title)
{
	/*glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // We want OpenGL 3.3
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL */
	m_window = glfwCreateWindow(m_width, m_height, title, nullptr, nullptr);
	if (m_window == nullptr)
	{
		Debug_Log("Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible\n");
		glfwTerminate();
	}
	glfwMakeContextCurrent(m_window);


}
Пример #8
0
void Chunk::update()
{
	if (shouldUpdate)
	{
		switch (m_genMethod)
		{
		case RANDOM:
			genRand(randBand(randEngine));
			break;
		case SPHERE:
			genSphere();
			break;
		case ALL:
			genAll();
			break;
		default:
			Debug_Log(" ERROR? : genMethod = NONE");
			break;
		}
	}
	shouldUpdate = false;
}
Пример #9
0
void Chunk::genRand(int numBlocks)
{
	int numActive = 0;

	if (numBlocks > (CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE))
	{
		Debug_Log("Bad input for randActive");
	}
	else
	{

		for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE; i++)
		{
			int x, y, z;
			x = roll(randEngine);
			y = roll(randEngine);
			z = roll(randEngine);

			if (randBool(randEngine))
			{
				if (!m_blocks[x][y][z].getActive())
				{
					m_blocks[x][y][z].setActive(true);
				}
				numActive++;
				if (numActive >= numBlocks / 3)
				{
					return;
				}
			}
			else
			{
				m_blocks[x][y][z].setActive(false);
			}
		}
	}
}
Пример #10
0
void Window::setWindowClose()
{
	glfwSetWindowShouldClose(m_window, GL_TRUE); ///< set the Window state to should close.
	Debug_Log("Window is set to close.");
}
Пример #11
0
void Window::destroy()
{
	glfwDestroyWindow(m_window);
	Debug_Log("Window " << m_title << " has been destoryed.");
	glfwTerminate(); ///< if there is more then 1 window, remove this line but make sure you terminate glfw somewhere else.
}
Пример #12
0
int main()
{
	if (!glfwInit()) // Initialize glfw and check for errors.
	{
		Debug_Log("glfw failed to init");
	}

	Window m_window; // Create a window.
	if (m_window.init(WINDOW_WITDH, WINDOW_HEIGHT)) // Initialize the window.
	{
		Debug_Log(m_window.getTitle() << " window has been initiated");
	}

	if (glewInit()) // Initialize glew and check for errors, please note that you must init glew after creating a window and initializing it, and before using any gl calls.
	{
		Debug_Log("glew failed to init");
	}

	InputManager m_inputManager; // Create an input manager object
	m_inputManager.init(m_window.getWindowHandler()); // Init it

	GLProgram m_program;// Create a GLProgram object for debug purposes
	m_program.loadShaders("Shaders/Shader.vert", "Shaders/Shader.frag"); // test if the shaders compile

	GLuint m_vao; /// this is the vertex array object, unimportant for now, and the program can run without it.
	glGenVertexArrays(1, &m_vao);
	glBindVertexArray(m_vao);

	Vertex2D verts[6];
	verts[0].setPosition(0.0f, 1.0f);
	verts[0].setColor(Color8(255, 255, 0));
	verts[1].setPosition(1.0f, 0.0f);
	verts[1].setColor(Color8(255, 0, 255));
	verts[2].setPosition(0.0f, 0.0f);
	verts[2].setColor(Color8(0, 255, 0));
	verts[3].setPosition(1.0f, 0.0f);
	verts[3].setColor(Color8(0, 0, 255));
	verts[4].setPosition(1.0f, 1.0f);
	verts[4].setColor(Color8(0, 255, 255));
	verts[5].setPosition(0.0f, 1.0f);
	verts[5].setColor(Color8(255, 0, 0));

	
	Debug_Log("size of vertecies" << sizeof(verts));
	Debug_Log(sizeof(Vertex3D));


	GLuint m_vbo; ///< this is the vertex buffer object.
	glGenBuffers(1, &m_vbo);
	glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
	glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);

	/*

	VERTEX:1
		POSITION - 1 
		COLOR - 1
		TEXTURE-COORD -1 
	VERTEX:2
		POSITION-1
		COLOR-1
		TEXTURE-COORD-1
	
	*/

	//glUseProgram(m_program.getID()); 
	m_program.addAttribute("vertexPos", 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), (void*)offsetof(Vertex2D,position));
	m_program.addAttribute("vertexColor", 3, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex2D), (void*)offsetof(Vertex2D, color));

	glm::mat4 projection; /*= glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);*/
	glm::mat4 view; /*glm::lookAt(glm::vec3(0.0, -5.0, 0.0), glm::vec3(0.0, 0.0, 0.0), glm::vec3(0.0, 0.0, 1.0));*/
	glm::mat4 model;/* = glm::mat4(1.0f);*/
	glm::mat4 MVP = projection * view * model;
	GLint mvpLocation = glGetUniformLocation(m_program.getID(), "MVP");
	glUniformMatrix4fv(mvpLocation, 1, GL_FALSE, glm::value_ptr(MVP));

	while (!m_window.shouldWindowClose()) // The game loop.
	{
		m_inputManager.update();

		if(m_inputManager.isKeyPressed(KEYS::ESC)) // Check if pressed escape.
		{	
			m_window.setWindowClose(); // Close the window if you press the escape button.
		}
		glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // set the background color
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		
		m_program.use();
		glDrawArrays(GL_TRIANGLES, 0, 6);
		m_program.unuse();

		m_window.update(); // Update the window.
	}
	glDeleteBuffers(1, &m_vbo);
	glDeleteVertexArrays(1, &m_vao);
	m_program.deleteProgram();
	m_window.destroy();
	return 0;
}
Пример #13
0
void Window::setWindowClose()
{
	glfwSetWindowShouldClose(m_window,GL_TRUE);
	Debug_Log("Window set to close");
}
Пример #14
0
Window::~Window()
{
	glfwDestroyWindow(m_window);
	Debug_Log("Window Terminated")
	glfwTerminate();
}