Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "graphics_framework.h"
- #include <glm/glm.hpp>
- #include <glm/gtx/rotate_vector.hpp>
- using namespace std;
- using namespace graphics_framework;
- using namespace glm;
- target_camera cam;
- GLuint noise_texture;
- const int noise_width = 512;
- const int noise_height = noise_width;
- GLfloat noise_data[noise_height * noise_width];
- mesh example_sphere;
- effect sphere_eff;
- bool load_content() {
- example_sphere = mesh(geometry_builder::create_sphere());
- sphere_eff.add_shader("tuisku/shader.vert", GL_VERTEX_SHADER);
- sphere_eff.add_shader("tuisku/shader.frag", GL_FRAGMENT_SHADER);
- sphere_eff.build();
- cam.set_position(vec3(5.0f, 5.0f, 5.0f));
- cam.set_target(vec3(0.0f, 0.0f, 0.0f));
- auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height());
- cam.set_projection(1.0472f, aspect, 2.414f, 1000.0f);
- for (auto& f : noise_data)
- {
- //Please don't do random numbers like this, but it works
- f = (float)rand() / (float)RAND_MAX;
- }
- //Creat the texture
- glGenTextures(1, &noise_texture);
- //Bind it
- glBindTexture(GL_TEXTURE_2D, noise_texture);
- //Send the Data
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, noise_width, noise_height, 0, GL_RED, GL_FLOAT, noise_data);
- //Set the parameters
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- return true;
- }
- bool update(float delta_time) {
- example_sphere.get_transform().rotate(vec3(0, delta_time, 0));
- cam.update(delta_time);
- return true;
- }
- bool render() {
- renderer::bind(sphere_eff);
- auto V = cam.get_view();
- auto P = cam.get_projection();
- auto MVP_sphere = P * V * example_sphere.get_transform().get_transform_matrix();
- glUniformMatrix4fv(sphere_eff.get_uniform_location("MVP"), 1, GL_FALSE, value_ptr(MVP_sphere));
- //------------------------------------------
- // Set active texture unit (unit 0)
- glActiveTexture(GL_TEXTURE0);
- // Bind texture to that unit (unit 0)
- glBindTexture(GL_TEXTURE_2D, noise_texture);
- // Set tex uniform to that unit (unit 0)
- glUniform1i(sphere_eff.get_uniform_location("tex"), 0);
- //------------------------------------------
- //^that is the equivilent of doing renderer::bind(noise_texture, 0), but with pure opengl.
- renderer::render(example_sphere);
- return true;
- }
- int main() {
- app application("", renderer::windowed);
- application.set_load_content(load_content);
- application.set_update(update);
- application.set_render(render);
- application.run();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement