GUI_Layered::GUI_Layered(GUI *gui) : gui(gui), canvas(gui->get_app()->get_canvas()), wm(*gui->get_app()->get_window()) { gui_manager = clan::GUIManager(wm, gui->get_theme_location()); wm.func_input_intercept() = bind_member(this, &GUI_Layered::wm_input_intercept); // Use a texture group to store all the gui textures clan::TextureGroup texture_group(clan::Size(1024, 1024)); wm.set_texture_group(texture_group); // Note: This line is optional setup_shader(); wobble_offset = 0.0f; last_time = clan::System::get_time(); lens_zoom = 3.2f; lens_near = 0.1f; lens_far = 10000.0f; lens_aspect = 1.0f; // Note, clan::GUIManager deletes these automatically, after GUI_Direct has gone out of scope in the clan::GUIManager destructor lineedit = new LineEdit(gui_manager); slider = new Slider(gui_manager); radiobutton = new RadioButton(gui_manager); scrollbar = new ScrollBar(gui_manager); menubar = new MenuBar(gui_manager, gui->get_resources_internal()); spin = new Spin(gui_manager); combobox = new ComboBox(gui_manager); panel3d = new Panel3D(gui_manager); }
static void loadShader(const char* vs_path , const char* fs_path) { // Need to delete the previous shader program glDeleteProgram(program); program = setup_shader(readfile(vs_path).c_str(), readfile(fs_path).c_str()); int sun = add_obj(program, "sun.obj","sun.bmp"); glEnable(GL_DEPTH_TEST); glCullFace(GL_BACK); }
int setup_capture_display(Sourceparams_t * sourceparams, Displaydata_t * displaydata, int * argc, char * argv[]) { int status, retval; char *shaderfilename; status = setup_display_params(sourceparams, displaydata); if (-1 == status) { retval = -1; } else { status = setup_capture_display_window(displaydata, sourceparams, argc, argv); if (-1 == status) { retval = -1; } else { /* need to set up opengl to get the texture units initialized */ /* before I can feed them to the shader */ status = init_ogl_video(displaydata, sourceparams); if (-1 == status) { retval = -1; } else { shaderfilename = select_shader_file(sourceparams); status = setup_shader(shaderfilename, sourceparams, displaydata); if (-1 == status) { retval = -1; } else { retval = 0; } } } } return(retval); }
int read_shaders(const char *filename) { /* If this gets more advanced we will switch to libconfuse, but right now we save that dependency */ int ret = 0; FILE *fd = fopen(filename, "r"); char line[128]; shader_count = 0; current_shader = 0; transition_offset_x = 0; if(!fd) { return -1; } while(shader_count < MAX_SHADERS && fgets(line, sizeof(line), fd)) { float time; char filename[sizeof(line)]; if(sscanf(line, "%f %s", &time, filename) == 2) { unsigned int prog; enum e_shader_type type = REAL_SHADER; if(filename[0] == '/') { /* Special hack to address some internal GL routines */ prog = atoi(filename+1); type = GL_CODE; } else if(!(prog = setup_shader(filename))) { ret = -1; break; } shaders[shader_count].time = time; shaders[shader_count].prog = prog; shaders[shader_count].type = type; shader_count++; } } fclose(fd); if(!shader_count) { ret = -1; } return ret; }
int main(int argc, char *argv[]) { GLFWwindow* window; glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); // OpenGL 3.3, Mac OS X is reported to have some problem. However I don't have Mac to test glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // For Mac OS X glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); window = glfwCreateWindow(1280, 960, "Mesh Smoothing Demo", NULL, NULL); if (!window) { glfwTerminate(); return EXIT_FAILURE; } glfwMakeContextCurrent(window); // This line MUST put below glfwMakeContextCurrent glewExperimental = GL_TRUE; glewInit(); // Enable vsync glfwSwapInterval(1); // Setup input callback glfwSetKeyCallback(window, key_callback); glfwSetMouseButtonCallback(window, mouse_callback); setup_gui_texture(); setup_gui_render_obj(); filenames[0] = "smoothing"; filenames[1] = "/ori/"; filenames[2] = "/lap/"; filenames[3] = "/tau/"; // load shader program shaders[0] = setup_shader(readfile("shaders/vs.txt").c_str(), readfile("shaders/fs.txt").c_str()); gui_shader = setup_shader(readfile("shaders/guivs.txt").c_str(), readfile("shaders/guifs.txt").c_str()); shaders[1] = setup_shader(readfile("shaders/nvs.txt").c_str(), readfile("shaders/nfs.txt").c_str()); shaders[2] = setup_shader(readfile("shaders/fvs.txt").c_str(), readfile("shaders/ffs.txt").c_str()); printf("we have:%d, %d, %d\n", shaders[0], shaders[1], shaders[2]); program1 = shaders[0]; show_obj = add_obj("smoothing/ori/bunny.obj"); glm::vec3 light_pos(0.0f, 0.0f, 0.0f); camera_location = glm::vec4(0.0f, 0.0f, 2.0f, 1.0f); up_direction = glm::vec4(0.0f, 1.0f, 0.0f, 1.0f); glEnable(GL_DEPTH_TEST); glCullFace(GL_BACK); glm::vec3 camera_location_xyz = glm::vec3(camera_location.x, camera_location.y, camera_location.z); glm::vec3 up_direction_xyz = glm::vec3(up_direction.x, up_direction.y, up_direction.z); setUniformMat4(shaders[0], "p", glm::perspective(glm::radians(45.0f), 640.0f/480, 0.1f, 100.f) *glm::mat4(1.0f)); setUniformMat4(shaders[0], "v", glm::lookAt(camera_location_xyz, glm::vec3(0.0f), glm::vec3(0, 1, 0))*glm::mat4(1.0f)); setUniformMat4(shaders[1], "p", glm::perspective(glm::radians(45.0f), 640.0f/480, 0.1f, 100.f) *glm::mat4(1.0f)); setUniformMat4(shaders[1], "v", glm::lookAt(camera_location_xyz, glm::vec3(0.0f), glm::vec3(0, 1, 0))*glm::mat4(1.0f)); setUniformMat4(shaders[2], "p", glm::perspective(glm::radians(45.0f), 640.0f/480, 0.1f, 100.f) *glm::mat4(1.0f)); setUniformMat4(shaders[2], "v", glm::lookAt(camera_location_xyz, glm::vec3(0.0f), glm::vec3(0, 1, 0))*glm::mat4(1.0f)); glm::mat4 rot; glm::mat4 rev; float last, start; last = start = glfwGetTime(); float fps = 0; while (!glfwWindowShouldClose(window)) { rotate(); zoom(); camera_location_xyz = glm::vec3(camera_location.x, camera_location.y, camera_location.z); up_direction_xyz = glm::vec3(up_direction.x, up_direction.y, up_direction.z); setUniformMat4(shaders[0], "v", glm::lookAt(camera_location_xyz, glm::vec3(0.0f), up_direction_xyz)*glm::mat4(1.0f)); setUniformMat4(shaders[1], "v", glm::lookAt(camera_location_xyz, glm::vec3(0.0f), up_direction_xyz)*glm::mat4(1.0f)); setUniformMat4(shaders[2], "v", glm::lookAt(camera_location_xyz, glm::vec3(0.0f), up_direction_xyz)*glm::mat4(1.0f)); render(); glfwSwapBuffers(window); glfwPollEvents(); fps++; if(glfwGetTime() - last > 1.0) { std::cout<<(double)fps/(glfwGetTime()-last)<<std::endl; fps = 0; last = glfwGetTime(); } } releaseObjects(); glfwDestroyWindow(window); glfwTerminate(); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { GLFWwindow* window; glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); // OpenGL 3.3, Mac OS X is reported to have some problem. However I don't have Mac to test glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); //set hint to glfwCreateWindow, (target, hintValue) glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); //hint--> window not resizable, explicit use core-profile, opengl version 3.3 // For Mac OS X glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); window = glfwCreateWindow(800, 600, "Simple Example", NULL, NULL); if (!window) { glfwTerminate(); return EXIT_FAILURE; } glfwMakeContextCurrent(window); //set current window as main window to focus // This line MUST put below glfwMakeContextCurrent glewExperimental = GL_TRUE; //tell glew to use more modern technique for managing OpenGL functionality glewInit(); // Enable vsync glfwSwapInterval(1); glProvokingVertex(GL_FIRST_VERTEX_CONVENTION); // Setup input callback glfwSetKeyCallback(window, key_callback); //set key event handler // load shader program program = setup_shader(readfile("flat_vs.txt").c_str(), readfile("flat_fs.txt").c_str()); program1 = setup_shader(readfile("gourand_vs.txt").c_str(), readfile("gourand_fs.txt").c_str()); program2 = setup_shader(readfile("phong_vs.txt").c_str(), readfile("phong_fs.txt").c_str()); program3 = setup_shader(readfile("blin_vs.txt").c_str(), readfile("blin_fs.txt").c_str()); int sun = add_obj(program, "sun.obj","sun.bmp"); int sun1 = add_obj(program1, "sun.obj", "sun.bmp"); int sun2 = add_obj(program2, "sun.obj", "sun.bmp"); int sun3 = add_obj(program3, "sun.obj", "sun.bmp"); glEnable(GL_DEPTH_TEST); // prevent faces rendering to the front while they're behind other faces. glCullFace(GL_BACK); // discard back-facing trangle // Enable blend mode for billboard //glEnable(GL_BLEND); //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //-----------------------------------------------------------setting view point----------------------------------// set_vp(program); set_vp(program1); set_vp(program2); set_vp(program3); //-----------------------------------------------------------end of setting--------------------------------------// //------------------------------------------------------setting viewing position---------------------------------// set_viewPosition(program); set_viewPosition(program1); set_viewPosition(program2); set_viewPosition(program3); //------------------------------------------------------end of setting-------------------------------------------// float last, start; last = start = glfwGetTime(); int fps=0; while (!glfwWindowShouldClose(window)) {//program will keep draw here until you close the window float delta = glfwGetTime() - start; render(); glfwSwapBuffers(window); //swap the color buffer and show it as output to the screen. glfwPollEvents(); //check if there is any event being triggered fps++; if(glfwGetTime() - last > 1.0) { std::cout<<(double)fps/(glfwGetTime()-last)<<std::endl; fps = 0; last = glfwGetTime(); } } releaseObjects(); glfwDestroyWindow(window); glfwTerminate(); return EXIT_SUCCESS; }