// init programs here, this will be done only once: void SoTriangles::init (const char *file, GLuint *textures) { // Build program: _vsh.load_and_compile ( GL_VERTEX_SHADER, "../shaders/vsh_smtl_tex_gouraud.glsl" ); _fsh.load_and_compile ( GL_FRAGMENT_SHADER, "../shaders/fsh_tex_gouraud.glsl" ); _prog.init_and_link ( _vsh, _fsh ); // Define buffers needed: gen_vertex_arrays ( 1 ); // will use at least 1 vertex array gen_buffers ( 2 ); // will use at least 1 buffer _prog.uniform_locations (11); // declare here uniforms //_prog.uniform_location ( 0, "vTransf" ); // each name must appear in the shader //_prog.uniform_location ( 1, "vProj" ); //... _prog.uniform_location(0, "vTransf"); _prog.uniform_location(1, "vProj"); _prog.uniform_location(2, "lPos"); _prog.uniform_location(3, "la"); _prog.uniform_location(4, "ld"); _prog.uniform_location(5, "ls"); _prog.uniform_location(6, "ka"); _prog.uniform_location(7, "kd"); _prog.uniform_location(8, "ks"); _prog.uniform_location(9, "sh"); _prog.uniform_location(10, "Tex1"); GsImage I; if (!I.load(file)) std::cout << "COULD NOT LOAD IMAGE!\n"; else std::cout << "loaded\n"; //glGenTextures(1, &id); // ids start at 1 glGenTextures(2, textures); glBindTexture(GL_TEXTURE_2D, *textures); glTexImage2D(GL_TEXTURE_2D, 0, 4, I.w(), I.h(), 0, GL_RGBA, GL_UNSIGNED_BYTE, I.data()); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glGenerateMipmap(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); glBindVertexArray(0); I.init(0, 0); // free image from CPU if (!I.load("../texture/sides.bmp")) std::cout << "COULD NOT LOAD IMAGE!\n"; else std::cout << "loaded\n"; glBindTexture(GL_TEXTURE_2D, textures[1]); glTexImage2D(GL_TEXTURE_2D, 0, 4, I.w(), I.h(), 0, GL_RGBA, GL_UNSIGNED_BYTE, I.data()); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glGenerateMipmap(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); glBindVertexArray(0); I.init(0, 0); // free image from CPU }
void SoModelWire::init(const GlProgram& prog, int part) { if (part == 0) { m.load("armmodel/rhand.m"); } else if (part == 1) { m.load("armmodel/rlowerarm.m"); } else if (part == 2) { m.load("armmodel/rupperarm.m"); } // Define buffers needed: set_program(prog); gen_vertex_arrays(1); // will use 1 vertex array gen_buffers(2); // will use 2 buffers: one for coordinates and one for colors uniform_locations(10); // will send 2 variables: the 2 matrices below uniform_location(0, "vTransf"); uniform_location(1, "vProj"); uniform_location(2, "lPos"); uniform_location(3, "la"); uniform_location(4, "ld"); uniform_location(5, "ls"); uniform_location(6, "ka"); uniform_location(7, "kd"); uniform_location(8, "ks"); uniform_location(9, "sh"); }
void SoCapsule::init(const GlProgram& prog) { // Define buffers needed: set_program(prog); gen_vertex_arrays(1); // will use 1 vertex array gen_buffers(2); // will use 2 buffers: one for coordinates and one for colors uniform_locations(2); // will send 2 variables: the 2 matrices below uniform_location(0, "vTransf"); uniform_location(1, "vProj"); }
// init is called only once: void SoCurve::init() { // Build program: _vsh.load_and_compile(GL_VERTEX_SHADER, "../shaders/vsh_mcol_flat.glsl"); _fsh.load_and_compile(GL_FRAGMENT_SHADER, "../shaders/fsh_flat.glsl"); _prog.init_and_link(_vsh, _fsh); // Define buffers needed: gen_vertex_arrays(1); // will use 1 vertex array gen_buffers(2); // will use 2 buffers: one for coordinates and one for colors _prog.uniform_locations(2); // will send 2 variables: the 2 matrices below _prog.uniform_location(0, "vTransf"); _prog.uniform_location(1, "vProj"); }
void SoPoly::init ( const GlProgram& prog, const GsColor& c, const GsColor& selc ) { _vsh.load_and_compile(GL_VERTEX_SHADER, "../vsh_mcol_flat.glsl"); _fsh.load_and_compile(GL_FRAGMENT_SHADER, "../fsh_flat.glsl"); _prog.init_and_link(_vsh, _fsh); // Define buffers needed: //set_program ( prog ); gen_vertex_arrays ( 1 ); // will use 1 vertex array gen_buffers ( 2 ); // will use 2 buffers: one for coordinates and one for colors _prog.uniform_locations ( 2 ); // will send 2 variables: the 2 matrices below _prog.uniform_location ( 0, "vTransf" ); _prog.uniform_location ( 1, "vProj" ); _color = c; _selcolor = selc; }
// init is called only once: void SoLines::init () { // Build program: // Note: the program below could be shared with SoAxis (no need to comppile both // because they are the same), but ok here to avoid adding code for sharing #if (defined WIN32) _vsh.load_and_compile ( GL_VERTEX_SHADER, "../vsh_mcol_flat.glsl" ); _fsh.load_and_compile ( GL_FRAGMENT_SHADER, "../fsh_flat.glsl" ); #else _vsh.load_and_compile ( GL_VERTEX_SHADER, "vsh_mcol_flat.glsl" ); _fsh.load_and_compile ( GL_FRAGMENT_SHADER, "fsh_flat.glsl" ); #endif _prog.init_and_link ( _vsh, _fsh ); // Define buffers needed: gen_vertex_arrays ( 1 ); // will use 1 vertex array gen_buffers ( 2 ); // will use 2 buffers: one for coordinates and one for colors _prog.uniform_locations ( 2 ); // will send 2 variables: the 2 matrices below _prog.uniform_location ( 0, "vTransf" ); _prog.uniform_location ( 1, "vProj" ); }
void SoModel::init () { // Load programs: _vshgou.load_and_compile ( GL_VERTEX_SHADER, "../shaders/vsh_mcol_gouraud.glsl" ); _fshgou.load_and_compile ( GL_FRAGMENT_SHADER, "../shaders/fsh_gouraud.glsl" ); _proggouraud.init_and_link ( _vshgou, _fshgou ); _vshphong.load_and_compile ( GL_VERTEX_SHADER, "../shaders/vsh_mcol_phong.glsl" ); _fshphong.load_and_compile ( GL_FRAGMENT_SHADER, "../shaders/fsh_mcol_phong.glsl" ); _progphong.init_and_link ( _vshphong, _fshphong ); // Define buffers needed: gen_vertex_arrays ( 1 ); // will use 1 vertex array gen_buffers ( 3 ); // will use 3 buffers _proggouraud.uniform_locations ( 9 ); // will send 9 variables _proggouraud.uniform_location ( 0, "vTransf" ); _proggouraud.uniform_location ( 1, "vProj" ); _proggouraud.uniform_location ( 2, "lPos" ); _proggouraud.uniform_location ( 3, "la" ); _proggouraud.uniform_location ( 4, "ld" ); _proggouraud.uniform_location ( 5, "ls" ); _proggouraud.uniform_location ( 6, "ka" ); _proggouraud.uniform_location ( 7, "ks" ); _proggouraud.uniform_location ( 8, "sh" ); _progphong.uniform_locations ( 9 ); // will send 9 variables _progphong.uniform_location ( 0, "vTransf" ); _progphong.uniform_location ( 1, "vProj" ); _progphong.uniform_location ( 2, "lPos" ); _progphong.uniform_location ( 3, "la" ); _progphong.uniform_location ( 4, "ld" ); _progphong.uniform_location ( 5, "ls" ); _progphong.uniform_location ( 6, "ka" ); _progphong.uniform_location ( 7, "ks" ); _progphong.uniform_location ( 8, "sh" ); }
/** * APPLE version of glGenVertexArraysAPPLE() * Arrays may live in VBOs or ordinary memory. */ void GLAPIENTRY _mesa_GenVertexArraysAPPLE(GLsizei n, GLuint *arrays) { GET_CURRENT_CONTEXT(ctx); gen_vertex_arrays(ctx, n, arrays); }
/** * ARB_direct_state_access * Generates ID's and creates the array objects. */ void GLAPIENTRY _mesa_CreateVertexArrays(GLsizei n, GLuint *arrays) { GET_CURRENT_CONTEXT(ctx); gen_vertex_arrays(ctx, n, arrays, true, "glCreateVertexArrays"); }
/** * ARB version of glGenVertexArrays() * All arrays will be required to live in VBOs. */ void GLAPIENTRY _mesa_GenVertexArrays(GLsizei n, GLuint *arrays) { GET_CURRENT_CONTEXT(ctx); gen_vertex_arrays(ctx, n, arrays, false, "glGenVertexArrays"); }