--- cvsroot/libgender/material.C 2004/10/23 21:43:27 1.14 +++ cvsroot/libgender/material.C 2004/10/29 15:58:50 1.15 @@ -12,7 +12,7 @@ } void -simple_material::begin () +simple_material::enable () { glMaterialfv (GL_FRONT, GL_DIFFUSE, (GLfloat *) & diffuse); glMaterialfv (GL_FRONT, GL_SPECULAR, (GLfloat *) & specular); @@ -21,32 +21,14 @@ } void -simple_material::end () +simple_material::disable () { } -void -osama_material::begin () -{ - cgGLEnableProfile (vsh_profile); - cgGLEnableProfile (fsh_profile); - cgGLEnableTextureParameter (g_Texture); -} - -void -osama_material::end () -{ - cgGLDisableTextureParameter (g_Texture); - // cgGLUnbindProgram (vsh_profile); - // cgGLUnbindProgram (fsh_profile); - cgGLDisableProfile (vsh_profile); - cgGLDisableProfile (fsh_profile); -} - GLuint texture::load_texture (SDL_Surface * surface, GLfloat * tex2oord) { - GLuint textur; + GLuint name; int w, h; SDL_Surface *image; SDL_Rect area; @@ -92,24 +74,60 @@ SDL_SetAlpha (surface, saved_flags, saved_alpha); /* Create an OpenGL texture for the image */ - glGenTextures (1, &textur); - glBindTexture (GL_TEXTURE_2D, textur); + glGenTextures (1, &name); + glBindTexture (GL_TEXTURE_2D, name); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameteri (GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); // GENERATE_MIPMAP_SGIS + glTexParameteri (GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels); SDL_FreeSurface (image); /* No longer needed */ - return textur; + return name; } -CGcontext cgc; +test_material::test_material () +: tex ("textures/osama.jpg"), texvar (tex.name) +{ + using namespace shader; -void -init_shaders () + p.vsh->start (); + + temp_4f lightpos; + temp_4f wpos; + + //lightpos = shader::vec4 (0, 10, 0, 1); + vout.position = shader::gl.model_view_projection_matrix * vin.vertex; + vout.tex_coord[0] = vin.tex_coord[0]; + //vout.tex_coord[1] = normalize (lightpos - wpos); + //vout.tex_coord[2] = normalize (wpos); + //vout.tex_coord[3] = normalize (xyz (gl.model_view_matrix_inverse_transpose) * vin.normal); + //vout.tex_coord[4] = normalize (xyz (gl.projection_matrix_inverse_transpose) - wpos); + + p.vsh->end (); + p.vsh->compile (); + + fragment_shader fsh; + + p.fsh->start (); + + xyz(fout.frag_color) = texture_2d (texvar, fin.tex_coord[0]); + + p.fsh->end (); + p.fsh->compile (); + p.link (); +} + +void test_material::enable () +{ + p.enable (); + texvar->enable (); +} + +void test_material::disable () { - cgc = cgCreateContext (); + texvar->disable (); + p.disable (); }