ModelManager::ModelManager() { ObjLoader objLoad; Texture* testTexture = new Texture(); testTexture->loadTexture("models/HouseTexture1.png"); Model *obj = objLoad.loadObj("models/House2.obj"); models["house"] = obj; textures["house"] = testTexture; Model *obj3 = objLoad.loadObj("models/militaryplane.obj"); Texture* planeText = new Texture(); planeText->loadTexture("models/textures/plane.png"); models["plane"] = obj3; textures["plane"] = planeText; }
int main(int argc, char** argv) { // @todo used for alter monitor or NULL when we're create window. string isDebug = (argc > 1 ? argv[1] : ""); glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); monitor = glfwGetPrimaryMonitor(); mode = glfwGetVideoMode(monitor); window = glfwCreateWindow(mode->width, mode->height, "Project Melkor - Roch Studio", NULL, NULL); if (!window) { cout << "could not create Window" << endl; glfwTerminate(); return -1; } // Setting Window pos Center in Monitor 1920 - 1080 // glfwSetWindowPos(window, 320, 180); glfwSetErrorCallback(error_callback); glfwSetKeyCallback(window, keyCallBack); glfwSetMouseButtonCallback(window, mouseButtonCallback); glfwSetCharModsCallback(window, character_callback); glfwSetCursorPosCallback(window, mouse_callback); glfwMakeContextCurrent(window); // @todo remove this line if (isDebug != "debug") { glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); } glewExperimental = GL_TRUE; if (glewInit() != GLEW_OK) { cout << "Failed to initialize Glew" << endl; return -1; } glMatrixMode(GL_PROJECTION); glViewport(0, 0, mode->width, mode->height); glMatrixMode(GL_MODELVIEW); Shader modelViewProjectionTextured( "assets/Shaders/ModelViewProjectionTextured.vert", "assets/Shaders/ModelViewProjectionTextured.frag" ); Shader modelViewProjectionColor( "assets/Shaders/ModelViewProjection.vert", "assets/Shaders/ModelViewProjection.frag" ); ProjectionMatrix projectionMatrix; projectionMatrix.setAspectRatio((GLfloat)mode->width / mode->height); int imageW, imageH; unsigned char *dirtTexture; Entity *entity[50]; Cube *cubes[50]; for (int i = 0; i < 50; i++) { // int num = (i >= 10 ? (i / 10) : 0); // entity[i] = new Entity(0, vec3((i * 1), -2, (num * -1)), 0, 0, 0, 1); // if (i < 10) entity[i] = new Entity(0, vec3(i * 1, -2, 0), 0, 0, 0, 1); else if (i >= 10 && i < 20) entity[i] = new Entity(0, vec3((i - 10) * 1, -2, -1), 0, 0, 0, 1); else if (i >= 20 && i < 30) entity[i] = new Entity(0, vec3((i - 20) * 1, -2, -2), 0, 0, 0, 1); else if (i >= 30 && i < 40) entity[i] = new Entity(0, vec3((i - 30) * 1, -2, -3), 0, 0, 0, 1); else if (i >= 40 && i < 50) entity[i] = new Entity(0, vec3((i - 40) * 1, -2, -4), 0, 0, 0, 1); cubes[i] = new Cube(mode->width, mode->height); cubes[i]->setEntity(*entity[i]); cubes[i]->shader(&modelViewProjectionTextured); dirtTexture = SOIL_load_image((i >= 30 ? "assets/images/stone.jpg" : "assets/images/dirt.jpg"), &imageW, &imageH, 0, SOIL_LOAD_RGB); cubes[i]->textureImage(dirtTexture, imageW, imageH, GL_RGB); } // ### Font Configs Shader fontShader("assets/Shaders/FontVertexShader.glsl", "assets/Shaders/FontFragmentShader.glsl"); FontConfigs fontConfigs(18); // ### End Font Configs TextDraw playerText(&fontShader, mode->width, mode->height); playerText.characters(fontConfigs.Characters); playerText.color(glm::vec3(0.5, 0.8f, 0.2f)); Loader loader; ObjLoader stallObj = ObjLoader(); RawModel firstRawModel = stallObj.loadObj("assets/Models/stall.obj", loader); ObjModel stallModel(modelViewProjectionTextured, firstRawModel); unsigned char *stallTexture = SOIL_load_image("assets/images/stallTexture.png", &imageW, &imageH, 0, SOIL_LOAD_RGB); stallModel.textureImage(stallTexture, imageW, imageH, GL_RGB); Entity test(0, vec3(0, 0, 0), 0, 0, 0, 1); stallModel.setEntity(test); while (!glfwWindowShouldClose(window)) { // Check and call events glfwPollEvents(); // Game Logic here glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(0.0, 0.0, 0.0, 1.0f); // Set frame time GLfloat currentFrame = glfwGetTime(); deltaTime = currentFrame - lastFrame; lastFrame = currentFrame; Do_Movement(); // Render Text playerText.x(1.0f); playerText.y(1.0f); playerText.scale(1.0f); playerText.text("Created By Cod3r Kane"); playerText.render(); for (int i = 0; i < 50; i++) { cubes[i]->setViewMatrix(camera.GetViewMatrix()); cubes[i]->setProjectionMatrix(projectionMatrix); cubes[i]->render(); } stallModel.setViewMatrix(camera.GetViewMatrix()); stallModel.setProjectionMatrix(projectionMatrix); stallModel.render(); glfwSwapBuffers(window); // clean inputs keyboardkey = 0; charCodePoint = 0; } glfwDestroyWindow(window); glfwTerminate(); return 0; }