static int init_gl() { EGLint major, minor, n; GLuint vertex_shader, fragment_shader; GLint ret; program = make_program_object("src/gles/shaders/cube.vert", "src/gles/shaders/cube.frag"); glUseProgram(program); glBindAttribLocation(program, 0, "in_position"); glBindAttribLocation(program, 1, "in_normal"); glBindAttribLocation(program, 2, "in_color"); glBindAttribLocation(program, 3, "in_texuv"); modelviewmatrix = glGetUniformLocation(program, "modelviewMatrix"); modelviewprojectionmatrix = glGetUniformLocation(program, "modelviewprojectionMatrix"); normalmatrix = glGetUniformLocation(program, "normalMatrix"); texture_rgba_loc = glGetUniformLocation(program, "texture"); uniform_texture = glGetUniformLocation(program, "uniform_texture"); static struct pngload_attribute png_attr; load_png_image("utils/png-test.png", &png_attr); texture_id_rgba = gen_texture_from_data( png_attr.buf, png_attr.width, png_attr.height, png_color_type_GL(png_attr.color_type)); // Texture. /* glGenTextures(1, &texture_name); */ /* glBindTexture(GL_TEXTURE_2D, texture_name); */ // Bind the base texture glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture_id_rgba); // Set the base sampler to texture unit to 0 glUniform1i(texture_rgba_loc, 0); if (glGetError() != GL_NO_ERROR) { ERROR("glBindTexture!"); return -1; } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glUniform1i(uniform_texture, 0); glViewport(0, 0, 512, 512); return 0; }
static int init_gl() { EGLint major, minor, n; GLuint vertex_shader, fragment_shader; GLint ret; program = make_program_object("src/gles/shaders/cube3.vert", "src/gles/shaders/cube3.frag"); glUseProgram(program); glBindAttribLocation(program, 0, "in_position"); glBindAttribLocation(program, 1, "in_normal"); glBindAttribLocation(program, 2, "in_color"); modelviewmatrix = glGetUniformLocation(program, "modelviewMatrix"); modelviewprojectionmatrix = glGetUniformLocation(program, "modelviewprojectionMatrix"); normalmatrix = glGetUniformLocation(program, "normalMatrix"); glViewport(0, 0, 512, 512); glEnable(GL_CULL_FACE); static struct pngload_attribute png_attr; load_png_image("utils/blender2opengles/cube.png", &png_attr); GLuint texture = gen_texture_from_data( png_attr.buf, png_attr.width, png_attr.height, png_color_type_GL(png_attr.color_type)); // Bind the base texture glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture); GLint texture_loc = glGetUniformLocation(program, "s_texture_rgba"); // Set the base sampler to texture unit to 0 glUniform1i(texture_loc, 0); return 0; }
void FileImage::load_file() { FSFile fp(filename.c_str(), "r"); if (!fp.is_open()) { printf("Could not open image \"%s\"\n", filename.c_str()); return; } int w, h, channels; image = load_png_image(fp, fp.get_size(), &w, &h, &channels); width = w; height = h; fp.close(); if (image == NULL) { printf("Could not load image \"%s\"\n", filename.c_str()); return; } if (!transparent.is_enabled()) return; #ifndef CHOWDREN_FORCE_TRANSPARENT if (channels != 1 && channels != 3) return; #endif for (int i = 0; i < width * height; i++) { unsigned char * c = &image[i*4]; if (c[0] != transparent.r || c[1] != transparent.g || c[2] != transparent.b) continue; c[3] = 0; } }
inline unsigned char * load_image(FSFile & image_file, int size, int * w, int * h, int * channels) { return load_png_image(image_file, size, w, h, channels); }
int t_main() { struct pngload_attribute png_attr; load_png_image("png-test.png", &png_attr); }