コード例 #1
0
ファイル: demo.cpp プロジェクト: idengxm/arcball
void Demo::create_arcball()
{
    auto blinn_phong_program = programs.create(BLINNPHONG_VS, BLINNPHONG_FS);
    auto shaded_pass = std::make_shared<gst::ShadedPass>(blinn_phong_program);
    shaded_pass->set_cull_face(gst::CullFace::BACK);
    shaded_pass->set_depth_test(true);

    auto material = gst::Material::create_struct("material");
    material.get_uniform("ambient") = glm::vec3(1.2f);
    material.get_uniform("diffuse") = glm::vec3(0.8f);
    material.get_uniform("specular") = glm::vec3(1.0f);
    material.get_uniform("emission") = glm::vec3(0.0f);
    material.get_uniform("shininess") = 21.0f;

    gst::MeshFactory mesh_factory(logger);
    auto suzanne = std::make_shared<gst::GroupNode>();
    for (auto mesh : mesh_factory.create_from_file(SUZANNE_OBJ)) {
        auto model = gst::Model(mesh, material, shaded_pass);
        auto model_node = std::make_shared<gst::ModelNode>(model);
        suzanne->add(model_node);
    }
    scene.add(suzanne);

    arcball = Arcball(suzanne);
    arcball.set_allow_constraints(true);

    arcball_helper = ArcballHelper::create(programs);
    arcball_helper.set_show_result(false);
}
コード例 #2
0
int init_resources() {
    /* Initialize the FreeType2 library */
    if (FT_Init_FreeType(&ft)) {
        fprintf(stderr, "Could not init freetype library\n");
        return 0;
    }

    /* Load a font */
    if (FT_New_Face(ft, "/Users/liesaweigert/ClionProjects/AR/assets/orange juice 2.0.ttf", 0, &face)) {
        fprintf(stderr, "Could not open font!\n");
        return 0;
    }

    program = create_program("/Users/liesaweigert/ClionProjects/AR/src/text.v.glsl", "/Users/liesaweigert/ClionProjects/AR/src/text.f.glsl");
    if(program == 0)
        return 0;

    attribute_coord = get_attrib(program, "coord");
    uniform_tex = get_uniform(program, "tex");
    uniform_color = get_uniform(program, "color");

    if(attribute_coord == -1 || uniform_tex == -1 || uniform_color == -1)
        return 0;

    // Create the vertex buffer object
    glGenBuffers(1, &vbo);

    return 1;
}
コード例 #3
0
ファイル: main.c プロジェクト: miguel-branco/mbench-islands
void
*worker_thread(void *arg)
{
	struct worker_args *args = arg;
	long *block = blocks[args->block];
	pthread_mutex_t *lock = locks[args->block];

#if defined(AFFINITY) && defined(__sun)
	if (processor_bind(P_LWPID, P_MYID, args->cpu, NULL)) {
		perror("processor_bind");
	}
#endif

	// initialize per-thread random number generator
	myrandstate_t r;
	init_myrand(&r, args->seed1, args->seed2);

	int c;
	long swap;
	int seq_i[batchsize];
	int seq_j[batchsize];

	for (;;) {
		for (c = 0; c < batchsize; c++) {
			seq_i[c] = get_uniform(&r) * blocksize;
			seq_j[c] = get_uniform(&r) * blocksize;
		}

		pthread_mutex_lock(lock);

		for (c = 0; c < batchsize; c++) {
			swap = block[seq_i[c]];
			block[seq_i[c]] = block[seq_j[c]];
			block[seq_j[c]] = swap;
		}

		pthread_mutex_unlock(lock);

#if defined(__sun)
		atomic_add_int(&counters[args->id], 1);
#endif

#if defined(linux)
		__sync_fetch_and_add(&counters[args->id], 1);
#endif

		//printf("[Thread %d] Using CPU %d\n", args->id, sched_getcpu());
	}

	return NULL;
}
コード例 #4
0
ファイル: main.cpp プロジェクト: robbor78/OpenGLTetris
int InitProgram() {
	programDepth = create_program("cube.v.glsl", "cube.f.glsl", vsDepth, fs);
	if (programDepth == 0)
		return 0;
	attribute_coord3d = get_attrib(programDepth, "vertex_position");
	attribute_normal = get_attrib(programDepth, "vertex_normal");
	attribute_colour = get_attrib(programDepth, "vertex_colour");

	uniform_m = get_uniform(programDepth, "model");
	uniform_v = get_uniform(programDepth, "view");
	uniform_p = get_uniform(programDepth, "projection");

	return 1;
}
コード例 #5
0
int main()
{
	int i;
	myrandstate_t r;

        int run = 500000;
        int nslots = 10;
	printf("\nGenerating %d random numbers in %d slots.\n", run, nslots);

	init_myrand(&r, 123, 456);

        int slots[nslots];
        for (i = 0; i < nslots; i++)
		slots[i] = 0;

        for (i = 0; i < run; i++) {
                uint32_t v = (uint32_t) (get_uniform(&r) * nslots);
                slots[v] += 1;
        }

	printf("\nSlots:\n======\n");

        for (i = 0; i < nslots; i++)
		printf("[%d]\t%d\n", i, slots[i]);
}
コード例 #6
0
ファイル: shader_glsl.c プロジェクト: W-MS/RetroArch
static GLuint compile_program(const char *vertex, const char *fragment, unsigned i)
{
   GLuint prog = glCreateProgram();
   if (!prog)
      return 0;

   GLuint vert = 0;
   GLuint frag = 0;

   if (vertex)
   {
      RARCH_LOG("Found GLSL vertex shader.\n");
      vert = glCreateShader(GL_VERTEX_SHADER);
      if (!compile_shader(vert, "#define VERTEX\n", vertex))
      {
         RARCH_ERR("Failed to compile vertex shader #%u\n", i);
         return false;
      }

      glAttachShader(prog, vert);
   }

   if (fragment)
   {
      RARCH_LOG("Found GLSL fragment shader.\n");
      frag = glCreateShader(GL_FRAGMENT_SHADER);
      if (!compile_shader(frag, "#define FRAGMENT\n", fragment))
      {
         RARCH_ERR("Failed to compile fragment shader #%u\n", i);
         return false;
      }

      glAttachShader(prog, frag);
   }

   if (vertex || fragment)
   {
      RARCH_LOG("Linking GLSL program.\n");
      if (!link_program(prog))
      {
         RARCH_ERR("Failed to link program #%u.\n", i);
         return 0;
      }

      // Clean up dead memory. We're not going to relink the program.
      // Detaching first seems to kill some mobile drivers (according to the intertubes anyways).
      if (vert)
         glDeleteShader(vert);
      if (frag)
         glDeleteShader(frag);

      glUseProgram(prog);
      GLint location = get_uniform(prog, "Texture");
      glUniform1i(location, 0);
      glUseProgram(0);
   }

   return prog;
}
コード例 #7
0
ファイル: shader_glsl.c プロジェクト: darlekc/RetroArch
static void find_uniforms_frame(GLuint prog, struct shader_uniforms_frame *frame, const char *base)
{
   char texture[64];
   char texture_size[64];
   char input_size[64];
   char tex_coord[64];

   snprintf(texture, sizeof(texture), "%s%s", base, "Texture");
   snprintf(texture_size, sizeof(texture_size), "%s%s", base, "TextureSize");
   snprintf(input_size, sizeof(input_size), "%s%s", base, "InputSize");
   snprintf(tex_coord, sizeof(tex_coord), "%s%s", base, "TexCoord");

   frame->texture      = get_uniform(prog, texture);
   frame->texture_size = get_uniform(prog, texture_size);
   frame->input_size   = get_uniform(prog, input_size);
   frame->tex_coord    = get_attrib(prog, tex_coord);
}
コード例 #8
0
ファイル: main.cpp プロジェクト: drumsetmonkey/voxel
// the function we use to initialize opengl and the world
static int init_resources(){
	started = false;
	shaderProgram = create_program("frig.vert","frig.frag");

	if(!shaderProgram)
		return 0;

	attribute_coord = get_attrib(shaderProgram, "coord");
	uniform_mvp = get_uniform(shaderProgram, "mvp");
	uniform_sampler = get_uniform(shaderProgram, "texture");

	if(attribute_coord == -1 || uniform_mvp == -1)
		return 0;

	if(ui::text::init_text()){
		std::cerr << "Could not initialize fonts!" << std::endl;
		return 0;
	}

	glEnableVertexAttribArray(attribute_coord);

	cameraPos = glm::vec3(32.0,64.0,32.0);
	cameraRot = glm::vec3(0,0,0);

	// GENERATE HERE
	sc = new SuperChunk();


	blockTexture = Texture::loadTexture("assets/blockStrip.png");

	glUseProgram(shaderProgram);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D,blockTexture);
	glUniform1f(uniform_sampler,0);

	glPolygonOffset(1, 1);
	
	glClearColor(0.6, 0.8, 1.0, 0.0);

	return 1;
}
コード例 #9
0
ファイル: canvas.cpp プロジェクト: chiqomar/GLassmt3
/* shade_fragment
 *
 * This is the fragment shader. The pixel color is determined here. Phong shading is also
 * done here.
 */
vec3f canvashdl::shade_fragment(vector<float> varying)
{
	const materialhdl *material;
	uniformhdl default_material;

	get_uniform("material", material);

	if (material != NULL)
		return material->shade_fragment(this, varying);
	else
		return default_material.shade_fragment(this, varying);
}
コード例 #10
0
ファイル: canvas.cpp プロジェクト: chiqomar/GLassmt3
/* shade_vertex
 *
 * This is the vertex shader. All transformations (normal, projection, modelview, etc)
 * should happen here. Flat and Gouraud shading, those are done here as
 * well.
 */
vec3f canvashdl::shade_vertex(vec8f v, vector<float> &varying)
{
	const materialhdl *material;
	uniformhdl default_material;

	get_uniform("material", material);

	if (material != NULL)
		return material->shade_vertex(this, v(0,3), v(3,6), varying);
	else
		return default_material.shade_vertex(this, v(0,3), v(3,6), varying);
}
コード例 #11
0
ファイル: shader_glsl.c プロジェクト: 6lackmag3/RetroArch
static void find_uniforms(glsl_shader_data_t *glsl,
                          unsigned pass, GLuint prog,
                          struct shader_uniforms *uni)
{
    unsigned i;
    char frame_base[64] = {0};

    glUseProgram(prog);

    uni->mvp           = get_uniform(glsl, prog, "MVPMatrix");
    uni->tex_coord     = get_attrib(glsl, prog, "TexCoord");
    uni->vertex_coord  = get_attrib(glsl, prog, "VertexCoord");
    uni->color         = get_attrib(glsl, prog, "Color");
    uni->lut_tex_coord = get_attrib(glsl, prog, "LUTTexCoord");

    uni->input_size    = get_uniform(glsl, prog, "InputSize");
    uni->output_size   = get_uniform(glsl, prog, "OutputSize");
    uni->texture_size  = get_uniform(glsl, prog, "TextureSize");

    uni->frame_count     = get_uniform(glsl, prog, "FrameCount");
    uni->frame_direction = get_uniform(glsl, prog, "FrameDirection");

    for (i = 0; i < glsl->shader->luts; i++)
        uni->lut_texture[i] = glGetUniformLocation(prog, glsl->shader->lut[i].id);

    clear_uniforms_frame(&uni->orig);
    find_uniforms_frame(glsl, prog, &uni->orig, "Orig");
    clear_uniforms_frame(&uni->feedback);
    find_uniforms_frame(glsl, prog, &uni->feedback, "Feedback");

    if (pass > 1)
    {
        snprintf(frame_base, sizeof(frame_base), "PassPrev%u", pass);
        find_uniforms_frame(glsl, prog, &uni->orig, frame_base);
    }

    for (i = 0; i + 1 < pass; i++)
    {
        snprintf(frame_base, sizeof(frame_base), "Pass%u", i + 1);
        clear_uniforms_frame(&uni->pass[i]);
        find_uniforms_frame(glsl, prog, &uni->pass[i], frame_base);
        snprintf(frame_base, sizeof(frame_base), "PassPrev%u", pass - (i + 1));
        find_uniforms_frame(glsl, prog, &uni->pass[i], frame_base);

        if (*glsl->shader->pass[i].alias)
            find_uniforms_frame(glsl, prog, &uni->pass[i], glsl->shader->pass[i].alias);
    }

    clear_uniforms_frame(&uni->prev[0]);
    find_uniforms_frame(glsl, prog, &uni->prev[0], "Prev");
    for (i = 1; i < PREV_TEXTURES; i++)
    {
        snprintf(frame_base, sizeof(frame_base), "Prev%u", i);
        clear_uniforms_frame(&uni->prev[i]);
        find_uniforms_frame(glsl, prog, &uni->prev[i], frame_base);
    }

    glUseProgram(0);
}
コード例 #12
0
ファイル: brush.c プロジェクト: johnh530/electro
static void set_brush_uniform(struct brush *b, const char *n,
                              int r, int c, int d, const float *v)
{
    struct uniform *u;

    /* Apply the given values to the uniform cache and OpenGL state. */

    if ((u = get_uniform(b, n)))
    {
        set_uniform(u, r, c, d, v);
        use_uniform(b, u);
    }
}
コード例 #13
0
ファイル: demo.cpp プロジェクト: idengxm/arcball
void Demo::create_lights()
{
    auto create_light = [](glm::vec3 diffuse)
    {
        auto light = gst::Light::create_array("point_lights");
        light.get_uniform("ambient") = glm::vec3(0.0f);
        light.get_uniform("diffuse") = diffuse;
        light.get_uniform("specular") = glm::vec3(1.0f);
        light.get_uniform("attenuation.constant") = 1.0f;
        light.get_uniform("attenuation.linear") = 0.5f;
        light.get_uniform("attenuation.quadratic") = 0.03f;
        return light;
    };

    auto light_node0 = std::make_shared<gst::LightNode>(create_light(glm::vec3(0.0f, 0.0f, 1.0f)));
    light_node0->position = glm::vec3(1.8f, 1.2f, 1.0f);
    scene.add(light_node0);

    auto light_node1 = std::make_shared<gst::LightNode>(create_light(glm::vec3(1.0f, 0.0f, 0.0f)));
    light_node1->position = glm::vec3(-2.0f, 1.2f, 2.0f);
    scene.add(light_node1);
}
コード例 #14
0
ファイル: shader_glsl.c プロジェクト: 6lackmag3/RetroArch
static void find_uniforms_frame(glsl_shader_data_t *glsl,
                                GLuint prog,
                                struct shader_uniforms_frame *frame, const char *base)
{
    char texture[64]      = {0};
    char texture_size[64] = {0};
    char input_size[64]   = {0};
    char tex_coord[64]    = {0};

    snprintf(texture, sizeof(texture), "%s%s", base, "Texture");
    snprintf(texture_size, sizeof(texture_size), "%s%s", base, "TextureSize");
    snprintf(input_size, sizeof(input_size), "%s%s", base, "InputSize");
    snprintf(tex_coord, sizeof(tex_coord), "%s%s", base, "TexCoord");

    if (frame->texture < 0)
        frame->texture = get_uniform(glsl, prog, texture);
    if (frame->texture_size < 0)
        frame->texture_size = get_uniform(glsl, prog, texture_size);
    if (frame->input_size < 0)
        frame->input_size = get_uniform(glsl, prog, input_size);
    if (frame->tex_coord < 0)
        frame->tex_coord = get_attrib(glsl, prog, tex_coord);
}
コード例 #15
0
ファイル: shader_glsl.c プロジェクト: DukedDroid/RetroArch
static GLuint compile_program(const char *vertex, const char *fragment, unsigned i)
{
   GLuint prog = glCreateProgram();
   if (!prog)
      return 0;

   if (vertex)
   {
      RARCH_LOG("Found GLSL vertex shader.\n");
      GLuint shader = glCreateShader(GL_VERTEX_SHADER);
      if (!compile_shader(shader, "#define VERTEX\n", vertex))
      {
         RARCH_ERR("Failed to compile vertex shader #%u\n", i);
         return false;
      }

      glAttachShader(prog, shader);
   }

   if (fragment)
   {
      RARCH_LOG("Found GLSL fragment shader.\n");
      GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
      if (!compile_shader(shader, "#define FRAGMENT\n", fragment))
      {
         RARCH_ERR("Failed to compile fragment shader #%u\n", i);
         return false;
      }

      glAttachShader(prog, shader);
   }

   if (vertex || fragment)
   {
      RARCH_LOG("Linking GLSL program.\n");
      if (!link_program(prog))
      {
         RARCH_ERR("Failed to link program #%u.\n", i);
         return 0;
      }

      glUseProgram(prog);
      GLint location = get_uniform(prog, "Texture");
      glUniform1i(location, 0);
      glUseProgram(0);
   }

   return prog;
}
コード例 #16
0
ファイル: shader_glsl.c プロジェクト: DukedDroid/RetroArch
static void find_uniforms(unsigned pass, GLuint prog, struct shader_uniforms *uni)
{
   glUseProgram(prog);

   uni->mvp           = get_uniform(prog, "MVPMatrix");
   uni->tex_coord     = get_attrib(prog, "TexCoord");
   uni->vertex_coord  = get_attrib(prog, "VertexCoord");
   uni->color         = get_attrib(prog, "Color");
   uni->lut_tex_coord = get_attrib(prog, "LUTTexCoord");

   uni->input_size    = get_uniform(prog, "InputSize");
   uni->output_size   = get_uniform(prog, "OutputSize");
   uni->texture_size  = get_uniform(prog, "TextureSize");

   uni->frame_count     = get_uniform(prog, "FrameCount");
   uni->frame_direction = get_uniform(prog, "FrameDirection");

   for (unsigned i = 0; i < glsl_shader->luts; i++)
      uni->lut_texture[i] = glGetUniformLocation(prog, glsl_shader->lut[i].id);

   char frame_base[64];
   clear_uniforms_frame(&uni->orig);
   find_uniforms_frame(prog, &uni->orig, "Orig");
   if (pass > 1)
   {
      snprintf(frame_base, sizeof(frame_base), "PassPrev%u", pass);
      find_uniforms_frame(prog, &uni->orig, frame_base);
   }

   for (unsigned i = 0; i < GFX_MAX_SHADERS; i++)
   {
      snprintf(frame_base, sizeof(frame_base), "Pass%u", i + 1);
      clear_uniforms_frame(&uni->pass[i]);
      find_uniforms_frame(prog, &uni->pass[i], frame_base);
      if (i && pass > i + 1)
      {
         snprintf(frame_base, sizeof(frame_base), "PassPrev%u", pass - i);
         find_uniforms_frame(prog, &uni->pass[i], frame_base);
      }
   }

   clear_uniforms_frame(&uni->prev[0]);
   find_uniforms_frame(prog, &uni->prev[0], "Prev");
   for (unsigned i = 1; i < PREV_TEXTURES; i++)
   {
      snprintf(frame_base, sizeof(frame_base), "Prev%u", i);
      clear_uniforms_frame(&uni->prev[i]);
      find_uniforms_frame(prog, &uni->prev[i], frame_base);
   }

   glUseProgram(0);
}
コード例 #17
0
ファイル: shader.hpp プロジェクト: Dzshiftt/Gnomescroll
    void init_shader()
    {
        GS_ASSERT(this->shader == NULL);
        delete this->shader;
        this->shader = new Shader;
        this->shader->set_debug(true);

        this->shader->load_shader("map_shader",
            MEDIA_PATH "shaders/terrain/terrain_map_mipmap_bilinear_ao.vsh",
            MEDIA_PATH "shaders/terrain/terrain_map_mipmap_bilinear_ao.fsh");
        //uniform
        InOffset  = shader->get_uniform("InOffset");
        //attribute
        InVertex =     shader->get_attribute("InVertex");
        InTexCoord =   shader->get_attribute("InTexCoord");
        InRGB =        shader->get_attribute("InRGB");
        InLightMatrix= shader->get_attribute("InLightMatrix");
        InLight=       shader->get_attribute("InLight");

        //int Normal=      shader->get_attribute("InTexCoord");
    }
コード例 #18
0
ファイル: FontEngine.cpp プロジェクト: Mikegrann/flood-fill
bool FontEngine::init() {
    if (FT_Init_FreeType(&library)) {
        INFO("FT_Init_FreeType");
        return 0;
    }

    program = create_program(VERTEX_SHADER_FILE, FRAGMENT_SHADER_FILE);
    if (!program) {
        INFO("Didn't Create Program");
        return 0;
    }

    coord = get_attrib(program, "coord");
    uniform_tex = get_uniform(program, "tex");
    uniform_color = get_uniform(program, "color");
    if (coord < 0 || uniform_tex < 0 || uniform_color < 0) {
        INFO("attribs not properly allocated");
        return 0;
    }

    billboard_program = create_program(VERTEX_SHADER_FILE_BILLBOARD, FRAGMENT_SHADER_FILE_BILLBOARD);
    if (!billboard_program) {
        INFO("Didn't Create BillBoard Program");
        return 0;
    }    

    billboard_pos = get_attrib(billboard_program, "position");
    billboard_coord = get_attrib(billboard_program, "texcoord");
    billboard_uniform_tex = get_uniform(billboard_program, "tex");
    billboard_uniform_color = get_uniform(billboard_program, "color");
    billboard_uniform_projection = get_uniform(billboard_program, "uProjection");
    billboard_uniform_view = get_uniform(billboard_program, "uView");
    
    
    if (billboard_pos < 0 || billboard_coord < 0|| billboard_uniform_tex < 0|| billboard_uniform_color< 0 || billboard_uniform_projection < 0 || billboard_uniform_view < 0) {
        INFO("billboard attribs not properly allocated");
        return 0;
        }

    glGenBuffers(1, &vbo);

    initialized = 1;
    return 1;
}
コード例 #19
0
ファイル: shader.cpp プロジェクト: PersonalBackup/ChernoCraft
void Shader::set_uniform_matrix(const char *name, glm::mat4 matrix) {
    glUniformMatrix4fv(get_uniform(name), 1, GL_FALSE, glm::value_ptr(matrix));
}
コード例 #20
0
void noob::graphics::init(uint32_t width, uint32_t height)
{
	uint32_t reset = BGFX_RESET_VSYNC;
	bgfx::reset(width, height, reset);
	
	bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x00000000, 1.0f, 0);
	bgfx::setViewClear(1, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x00000000, 1.0f, 0);
	bgfx::setState(BGFX_STATE_DEFAULT);
	/// Predefined uniforms (declared in `bgfx_shader.sh`):
	///   - `u_viewRect vec4(x, y, width, height)` - view rectangle for current
	///     view.
	///   - `u_viewTexel vec4(1.0/width, 1.0/height, undef, undef)` - inverse
	///     width and height
	///   - `u_view mat4` - view matrix
	///   - `u_invView mat4` - inverted view matrix
	///   - `u_proj mat4` - projection matrix
	///   - `u_invProj mat4` - inverted projection matrix
	///   - `u_viewProj mat4` - concatenated view projection matrix
	///   - `u_invViewProj mat4` - concatenated inverted view projection matrix
	///   - `u_model mat4[BGFX_CONFIG_MAX_BONES]` - array of model matrices.
	///   - `u_modelView mat4` - concatenated model view matrix, only first
	///     model matrix from array is used.
	///   - `u_modelViewProj mat4` - concatenated model view projection matrix.
	///   - `u_alphaRef float` - alpha reference value for alpha test.	
	// Add initial defaults (invalid stuff) to map
	
	bgfx::ProgramHandle h;
	h.idx = bgfx::invalidHandle;
	noob::graphics::shader shad;
	shad.program = h;

	noob::graphics::add_shader(std::string("invalid"), shad);

	noob::graphics::add_uniform(std::string("invalid"), bgfx::UniformType::Enum::Int1, 0);
	invalid_uniform = get_uniform("invalid");
	noob::graphics::add_uniform(std::string("colour_0"), bgfx::UniformType::Enum::Vec4, 1);
	colour_0 = get_uniform("colour_0");
	noob::graphics::add_uniform(std::string("colour_1"), bgfx::UniformType::Enum::Vec4, 1);
	colour_1 = get_uniform("colour_1");
	noob::graphics::add_uniform(std::string("colour_2"), bgfx::UniformType::Enum::Vec4, 1);
	colour_2 = get_uniform("colour_2");
	noob::graphics::add_uniform(std::string("colour_3"), bgfx::UniformType::Enum::Vec4, 1);
	colour_3 = get_uniform("colour_3");
	noob::graphics::add_uniform(std::string("blend_0"), bgfx::UniformType::Enum::Vec4, 1);
	blend_0 = get_uniform("blend_0");
	noob::graphics::add_uniform(std::string("blend_1"), bgfx::UniformType::Enum::Vec4, 1);
	blend_1 = get_uniform("blend_1");
	noob::graphics::add_uniform(std::string("scales"), bgfx::UniformType::Enum::Vec4, 1);
	scales = get_uniform("scales");
	noob::graphics::add_uniform(std::string("basic_light_0"), bgfx::UniformType::Enum::Vec4, 1);
	basic_light_0 = get_uniform("basic_light_0");
	noob::graphics::add_uniform(std::string("basic_light_1"), bgfx::UniformType::Enum::Vec4, 1);
	basic_light_1 = get_uniform("basic_light_1");
	noob::graphics::add_uniform(std::string("normal_mat"), bgfx::UniformType::Enum::Mat4, 1);
	normal_mat = get_uniform("normal_mat");

	noob::graphics::add_sampler(std::string("invalid"));
	invalid_texture = get_sampler("invalid");
	noob::graphics::add_sampler("texture_0");
	texture_0 = get_sampler("texture_0");

}
コード例 #21
0
ファイル: shader.cpp プロジェクト: PersonalBackup/ChernoCraft
void Shader::set_uniform_float1(const char *name, float data) {
    glUniform1f(get_uniform(name), data);
}
コード例 #22
0
ファイル: shader.cpp プロジェクト: PersonalBackup/ChernoCraft
void Shader::set_uniform_float4(const char *name, glm::vec4 data) {
    glUniform4f(get_uniform(name), data.x, data.y, data.z, data.w);
}
コード例 #23
0
ファイル: shader.cpp プロジェクト: PersonalBackup/ChernoCraft
void Shader::set_uniform_float3(const char *name, glm::vec3 data) {
    glUniform3f(get_uniform(name), data.x, data.y, data.z);
}
コード例 #24
0
ファイル: shader.cpp プロジェクト: PersonalBackup/ChernoCraft
void Shader::set_uniform_float2(const char *name, glm::vec2 data) {
    glUniform2f(get_uniform(name), data.x, data.y);
}
コード例 #25
0
ファイル: shader.cpp プロジェクト: PersonalBackup/ChernoCraft
void Shader::set_uniform_int(const char *name, GLuint data) {
    glUniform1i(get_uniform(name), data);
}
コード例 #26
0
ファイル: graph.cpp プロジェクト: alexbuicescu/Laboratoare
int init_resources() {
	program = create_program("graph.v.glsl", "graph.f.glsl");
	if (program == 0)
		return 0;

	attribute_coord2d = get_attrib(program, "coord2d");
	uniform_vertex_transform = get_uniform(program, "vertex_transform");
	uniform_texture_transform = get_uniform(program, "texture_transform");
	uniform_mytexture = get_uniform(program, "mytexture");
	uniform_color = get_uniform(program, "color");

	if (attribute_coord2d == -1 || uniform_vertex_transform == -1 || uniform_texture_transform == -1 || uniform_mytexture == -1)
		return 0;

	// Create our datapoints, store it as bytes
#define N 256
	GLbyte graph[N][N];

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			float x = (i - N / 2) / (N / 2.0);
			float y = (j - N / 2) / (N / 2.0);
			float d = hypotf(x, y) * 4.0;
			float z = (1 - d * d) * expf(d * d / -2.0);

			graph[i][j] = roundf(z * 127 + 128);
		}
	}

	/* Upload the texture with our datapoints */
	glActiveTexture(GL_TEXTURE0);
	glGenTextures(1, &texture_id);
	glBindTexture(GL_TEXTURE_2D, texture_id);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, N, N, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, graph);

	// Create two vertex buffer objects
	glGenBuffers(3, vbo);

	// Create an array for 101 * 101 vertices
	glm::vec2 vertices[101][101];

	for (int i = 0; i < 101; i++) {
		for (int j = 0; j < 101; j++) {
			vertices[i][j].x = (j - 50) / 50.0;
			vertices[i][j].y = (i - 50) / 50.0;
		}
	}

	// Tell OpenGL to copy our array to the buffer objects
	glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
	glBufferData(GL_ARRAY_BUFFER, sizeof vertices, vertices, GL_STATIC_DRAW);

	// Create an array of indices into the vertex array that traces both horizontal and vertical lines
	GLushort indices[100 * 100 * 6];
	int i = 0;

	for (int y = 0; y < 101; y++) {
		for (int x = 0; x < 100; x++) {
			indices[i++] = y * 101 + x;
			indices[i++] = y * 101 + x + 1;
		}
	}

	for (int x = 0; x < 101; x++) {
		for (int y = 0; y < 100; y++) {
			indices[i++] = y * 101 + x;
			indices[i++] = (y + 1) * 101 + x;
		}
	}

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo[1]);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, 100 * 101 * 4 * sizeof *indices, indices, GL_STATIC_DRAW);

	// Create another array of indices that describes all the triangles needed to create a completely filled surface
	i = 0;

	for (int y = 0; y < 100; y++) {
		for (int x = 0; x < 100; x++) {
			indices[i++] = y * 101 + x;
			indices[i++] = y * 101 + x + 1;
			indices[i++] = (y + 1) * 101 + x + 1;

			indices[i++] = y * 101 + x;
			indices[i++] = (y + 1) * 101 + x + 1;
			indices[i++] = (y + 1) * 101 + x;
		}
	}

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo[2]);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof indices, indices, GL_STATIC_DRAW);

	return 1;
}