Texture Font::render(const std::string & text, unsigned int size, const glm::vec4 & color) const { Assert(m_context, ""); auto i = m_fontBySize.find(size); if (i == m_fontBySize.end()) { auto result = m_fontBySize.emplace(size, std::unique_ptr<detail::TTF_Font_Wrapper>(new detail::TTF_Font_Wrapper(m_path, size))); Assert(result.second, ""); i = result.first; } auto & font = i->second; SDL_Color sdlColor; sdlColor.r = color.r * 255; sdlColor.g = color.g * 255; sdlColor.b = color.b * 255; sdlColor.a = color.a * 255; auto * surface = TTF_RenderText_Blended(font->font, text.c_str(), sdlColor); auto texture = m_context->createTexture(TextureLoader(surface).load()); SDL_FreeSurface(surface); return texture; }
void CubeObject::setTexture(char* inTex) { TextureLoader(&texture[0], inTex); printf("%d\n",texture[0]); }
//The main function int Main::start() { //Init if (init() == -1) { fprintf(stderr, "Could not initialise the program\n"); return -1; } //Create the scene Scene scene = Scene(window); Camera* camera = scene.getCamera(); camera->setFOV(45); //Create the loaders ModelLoader loader = ModelLoader(); TextureLoader textureLoader = TextureLoader(); //Create the models Model texturedModel = loader.loadToVao_OBJ_Textured("models/cube.obj", "textures/cube.bmp", glm::vec3(-3, 0, -5)); Model monkey = loader.loadToVao_OBJ("models/suzanne.obj", glm::vec3(0, 0, -5)); monkey.texture(textureLoader.loadBMP_custom("textures/suzanne texture.bmp")); monkey.setReflectivity(0.0); //Create an array of the same entities and add them to the scene std::vector<Entity> cubes; std::vector<glm::vec3> positions; int numOfCubes = 1000; Cube cubeTemp = Cube(); //Create the positions array for (int i = 0; i < numOfCubes; i++) { positions.insert(positions.end(), glm::vec3(rand() % 100, rand() % 100, rand() % 100)); } //Generate cloned cubes and put them at different positions cubes = cubeTemp.cloneEntity(positions); //Add the cubes to the entity map for (int i = 0; i < cubes.size(); i++) { scene.addEntity(&cubes[i]); } //Add the models to the scene scene.addModel(texturedModel); scene.addModel(monkey); //Create the onclick function auto onClick = []() { exit(0); }; //Create the UIs UIButton button = UIButton(0.06f, 0.05f, glm::vec2(1, -1), window, onClick); button.setAlignment(UIButton::ALIGN_BOTTOM_RIGHT); button.texture(textureLoader.loadBMP_custom("textures/Exit.bmp")); UIElement* ui = &button; //Add the UI scene.addPauseUI(ui); //Main loop while (!window.shouldClose()) { //Run the scene scene.run(); //Run the UI //Swap the buffers and poll events glfwSwapBuffers(window.getWindow()); glfwPollEvents(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } //Terminate glfw glfwTerminate(); return 0; }