I've been working, for a month, on an OpenGL library called alpha++. Basically, it is a framework that allows the user to create 3D scenes easily.
I would like to ask your advice on how I could make the user interface simpler. Here is the way I use my classes at the moment in Main.cpp:
Main.cpp
/// _______ _ _______ _______ _ _
/// ( ___ ( \ ( ____ |\ /( ___ ) ( ) ( )
/// | ( ) | ( | ( )| ) ( | ( ) | | | | |
/// | (___) | | | (____)| (___) | (___) |__| |__ __| |__
/// | ___ | | | _____| ___ | ___ (__ __(__ __)
/// | ( ) | | | ( | ( ) | ( ) | | | | |
/// | ) ( | (____/| ) | ) ( | ) ( | | | | |
/// |/ \(_______|/ |/ \|/ \| (_) (_)
/*
PLEASE IGNORE : this is a test file for the alpha++ library !
*/
#include <stdlib.h>
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include "utility.h"
#include "Shader.h"
#include "Window.h"
#include "Vertex.h"
#include "Mesh.h"
#include "Texture.h"
#include "Material.h"
#include "Transform.h"
#include "camera.h"
#include "ModelLoader.h"
#define WIDTH 1000.0
#define HEIGHT 900.0
#define FPS 120
using namespace alpha;
static volatile bool isRunning = false;
struct PhongLight{
glm::vec3 position;
glm::vec3 intensities; /// color of light
};
int main(int argc, char **argv)
{
Window window(300, 100, WIDTH, HEIGHT, "Oppa Win - e dooooow !", true);
///managing textures
Material material;
material.AddTexture("grid_metal", new Texture("res/Metal4.jpg", GL_TEXTURE_2D, GL_LINEAR));
material.AddTexture("modern_metal", new Texture("res/Metal5.jpg", GL_TEXTURE_2D, GL_LINEAR));
Mesh mesh("res/Test.obj");
///Shaders...
Shader shader;
shader.loadFromFile(GL_VERTEX_SHADER, "res/basicShader.glslv");
shader.loadFromFile(GL_FRAGMENT_SHADER, "res/phongShader.glslf");
shader.CreateAndLink();
shader.Bind();
shader.RegisterAttribute("position");
shader.RegisterAttribute("texCoord");
shader.RegisterAttribute("normal");
glBindAttribLocation(shader.GetProgramID(), shader.GetAttribLocation("position"), "position");
glBindAttribLocation(shader.GetProgramID(), shader.GetAttribLocation("texCoord"), "texCoord");
glBindAttribLocation(shader.GetProgramID(), shader.GetAttribLocation("normal"), "normal");
shader.RegisterUniform("modelView");
shader.RegisterUniform("MVP");
shader.RegisterUniform("time");
shader.RegisterUniform("lightPosition");
shader.RegisterUniform("lightIntensities");
///shader.RegisterUniform("lightDirection"); used for basic Fragment Shader
shader.UnBind();
Camera camera(glm::vec3(0, 0, -4), 70.0f, (float)window.GetWidth() / (float)window.GetHeight(), 0.01, 1000.0f);
Transform transform;
/// ///////////////////UNIFORMS //////////////////////// //
glm::mat4 modelView;
glm::mat4 projectionView;
glm::mat4 modelViewProjection;
glm::vec3 lightDirection = glm::vec3(0.5, 0.5, 0.5);
glm::vec2 screenResolution = glm::vec2(WIDTH, HEIGHT);
PhongLight phongLight;
phongLight.position = glm::vec3(4.0, 4.0, -4.0);
phongLight.intensities = glm::vec3(0.5, 0.5, 0.5);
///LOOP REALTED THINGS
float delta = 0.0f;
isRunning = true;
unsigned frameRate = 1000 / FPS;
Uint32 atStart = 0, atEnd = 0, elapsed = 0;
while (isRunning)
{
atStart = SDL_GetTicks();
window.Clear(0.0f, 0.0f, 0.0f, 0.0f);
///Updates
transform.GetRot() = glm::vec3(.0, delta * 500, .0);
modelView = transform.GetModelView();
projectionView = camera.GetViewProjection();
modelViewProjection = projectionView * modelView;
///Rendering
shader.Bind();
material.GetTexture("grid_metal")->Bind(0);
glUniformMatrix4fv(shader.GetUniformLocation("MVP"), 1, GL_FALSE, glm::value_ptr(modelViewProjection));
modelView = glm::mat4(1);///Light point doe not move !
glUniformMatrix4fv(shader.GetUniformLocation("modelView"), 1, GL_FALSE, glm::value_ptr(modelView));
glUniform1f(shader.GetUniformLocation("time"), delta);
///glUniform3fv(shader.GetUniformLocation("lightDirection"), 1, glm::value_ptr(lightDirection));
/// used for the basic fragment shader !
glUniform3fv(shader.GetUniformLocation("lightPosition"), 1, glm::value_ptr(phongLight.position));
glUniform3fv(shader.GetUniformLocation("lightIntensities"), 1, glm::value_ptr(phongLight.intensities));
mesh.Draw();
shader.UnBind();
delta += 0.002;
window.SwapBuffers();
window.Update();
isRunning = !window.isCloseRequested();
///FPS COUNT
atEnd = SDL_GetTicks();
elapsed = atEnd - atStart;
///SLEEP
if(elapsed < frameRate)
SDL_Delay(frameRate - elapsed);
}
return EXIT_SUCCESS;///YEHE ! EVERYTHING WENT RIGHT !
}
volatile
qualifier. Read about it here. – glampert Jun 15 at 21:25