| 1 |
root |
1.8 |
#include <cstdlib> |
| 2 |
|
|
#include <cstring> |
| 3 |
|
|
|
| 4 |
root |
1.9 |
#include <algorithm> |
| 5 |
|
|
|
| 6 |
root |
1.13 |
#include "opengl.h" |
| 7 |
|
|
#include "material.h" |
| 8 |
|
|
#include "util.h" |
| 9 |
|
|
|
| 10 |
root |
1.8 |
namespace shader { |
| 11 |
|
|
|
| 12 |
root |
1.9 |
refcounted::~refcounted () |
| 13 |
|
|
{ |
| 14 |
|
|
#if 0 |
| 15 |
|
|
if (refcnt) |
| 16 |
|
|
abort (); |
| 17 |
|
|
#endif |
| 18 |
|
|
} |
| 19 |
|
|
|
| 20 |
root |
1.12 |
const char str_float [] = "float"; |
| 21 |
|
|
const char str_vec2 [] = "vec2"; |
| 22 |
|
|
const char str_vec3 [] = "vec3"; |
| 23 |
|
|
const char str_vec4 [] = "vec4"; |
| 24 |
|
|
const char str_mat2 [] = "mat2"; |
| 25 |
|
|
const char str_mat3 [] = "mat3"; |
| 26 |
|
|
const char str_mat4 [] = "mat4"; |
| 27 |
|
|
|
| 28 |
|
|
const char str_sampler_1d [] = "sampler1D"; |
| 29 |
|
|
const char str_sampler_1d_shadow [] = "sampler1DShadow"; |
| 30 |
|
|
const char str_sampler_2d [] = "sampler2D"; |
| 31 |
|
|
const char str_sampler_2d_shadow [] = "sampler2DShadow"; |
| 32 |
|
|
const char str_sampler_2d_rect [] = "sampler2DRect"; |
| 33 |
|
|
const char str_sampler_2d_rect_shadow [] = "sampler2DRectShadow"; |
| 34 |
|
|
const char str_sampler_3d [] = "sampler3D"; |
| 35 |
|
|
const char str_sampler_3d_rect [] = "sampler3DRect"; |
| 36 |
|
|
const char str_sampler_cube [] = "samplerCube"; |
| 37 |
root |
1.11 |
|
| 38 |
root |
1.13 |
unsigned int var_i::next_id = 0; |
| 39 |
root |
1.8 |
|
| 40 |
root |
1.9 |
var_i::var_i (CGtype cgtype, const char *typestr) |
| 41 |
|
|
: typestr (typestr) |
| 42 |
root |
1.8 |
{ |
| 43 |
root |
1.13 |
//param = cgCreateParameter (cg_context, cgtype); |
| 44 |
root |
1.8 |
} |
| 45 |
|
|
|
| 46 |
|
|
var_i::~var_i () |
| 47 |
|
|
{ |
| 48 |
root |
1.13 |
//cgDestroyParameter (param); |
| 49 |
root |
1.8 |
} |
| 50 |
|
|
|
| 51 |
root |
1.13 |
temporary_i::temporary_i (CGtype cgtype, const char *strtype) |
| 52 |
|
|
: var_i (cgtype, strtype) |
| 53 |
|
|
{ |
| 54 |
|
|
sprintf (name, "T%lx_%d", ((long)this >> 4) & 0xfff, ++next_id); |
| 55 |
|
|
} |
| 56 |
|
|
|
| 57 |
|
|
uniform_i::uniform_i (CGtype cgtype, const char *strtype) |
| 58 |
|
|
: var_i (cgtype, strtype), dirty (true) |
| 59 |
|
|
{ |
| 60 |
|
|
sprintf (name, "U%lx_%d", ((long)this >> 4) & 0xfff, ++next_id); |
| 61 |
|
|
} |
| 62 |
|
|
|
| 63 |
|
|
//////////////////////////////////////////////////////////////////////////// |
| 64 |
|
|
|
| 65 |
root |
1.9 |
void var_i::build_decl (ostringstream &b) |
| 66 |
|
|
{ |
| 67 |
root |
1.13 |
b << typestr << ' ' << name; |
| 68 |
root |
1.9 |
} |
| 69 |
|
|
|
| 70 |
|
|
void uniform_i::build_decl (ostringstream &b) |
| 71 |
|
|
{ |
| 72 |
root |
1.13 |
b << "uniform " << typestr << ' ' << name; |
| 73 |
root |
1.9 |
} |
| 74 |
|
|
|
| 75 |
|
|
void stream_i::build_decl (ostringstream &b) |
| 76 |
|
|
{ |
| 77 |
root |
1.13 |
b << typestr << ' ' << name; |
| 78 |
|
|
} |
| 79 |
|
|
|
| 80 |
|
|
//////////////////////////////////////////////////////////////////////////// |
| 81 |
|
|
|
| 82 |
|
|
void glvar_i::build (shader_builder &b) |
| 83 |
|
|
{ |
| 84 |
|
|
b << name; |
| 85 |
root |
1.9 |
} |
| 86 |
|
|
|
| 87 |
root |
1.8 |
void var_i::build (shader_builder &b) |
| 88 |
|
|
{ |
| 89 |
root |
1.13 |
b << name; |
| 90 |
root |
1.8 |
} |
| 91 |
|
|
|
| 92 |
root |
1.9 |
void uniform_i::build (shader_builder &b) |
| 93 |
root |
1.8 |
{ |
| 94 |
root |
1.9 |
var_i::build (b); |
| 95 |
|
|
|
| 96 |
|
|
if (find (b.refs.begin (), b.refs.end (), uniform (*this)) == b.refs.end ()) |
| 97 |
|
|
b.refs.push_back (*this); |
| 98 |
root |
1.8 |
} |
| 99 |
|
|
|
| 100 |
root |
1.9 |
void stream_i::build (shader_builder &b) |
| 101 |
root |
1.8 |
{ |
| 102 |
root |
1.13 |
var_i::build (b); |
| 103 |
root |
1.9 |
|
| 104 |
|
|
if (find (b.streams.begin (), b.streams.end (), var (*this)) == b.streams.end ()) |
| 105 |
|
|
b.streams.push_back (*this); |
| 106 |
|
|
} |
| 107 |
|
|
|
| 108 |
|
|
void temporary_i::build (shader_builder &b) |
| 109 |
|
|
{ |
| 110 |
|
|
var_i::build (b); |
| 111 |
|
|
|
| 112 |
|
|
if (find (b.temps.begin (), b.temps.end (), var (*this)) == b.temps.end ()) |
| 113 |
|
|
b.temps.push_back (*this); |
| 114 |
|
|
} |
| 115 |
|
|
|
| 116 |
root |
1.13 |
void fragment_vector_i::build (shader_builder &b) |
| 117 |
|
|
{ |
| 118 |
|
|
for (vector<fragment>::iterator i = begin (); i != end (); i++) |
| 119 |
|
|
(*i)->build (b); |
| 120 |
|
|
} |
| 121 |
|
|
|
| 122 |
root |
1.9 |
void fragment_const_string_i::build (shader_builder &b) |
| 123 |
|
|
{ |
| 124 |
|
|
b << str; |
| 125 |
root |
1.8 |
} |
| 126 |
|
|
|
| 127 |
root |
1.13 |
void statement_i::build (shader_builder &b) |
| 128 |
|
|
{ |
| 129 |
|
|
b << " "; |
| 130 |
|
|
fragment_vector_i::build (b); |
| 131 |
|
|
b << ";\n"; |
| 132 |
|
|
} |
| 133 |
|
|
|
| 134 |
|
|
//////////////////////////////////////////////////////////////////////////// |
| 135 |
|
|
|
| 136 |
root |
1.9 |
struct vin vin; |
| 137 |
|
|
|
| 138 |
root |
1.12 |
varying_3f vin::position_3f ("gl_Vertex"); |
| 139 |
|
|
varying_4f vin::position_4f ("gl_Vertex"); |
| 140 |
|
|
varying_3f vin::normal_3f ("gl_Normal"); |
| 141 |
|
|
varying_3f vin::color_3f ("gl_Color"); |
| 142 |
|
|
varying_4f vin::color_4f ("gl_Color"); |
| 143 |
|
|
varying_3f vin::color2_3f ("gl_SecondaryColor"); |
| 144 |
|
|
varying_4f vin::color2_4f ("gl_SecondaryColor"); |
| 145 |
root |
1.11 |
varying_1f vin::texcoord_1f[8] = |
| 146 |
|
|
{ |
| 147 |
root |
1.13 |
varying_1f ("gl_TexCoord[0]"), varying_1f ("gl_TexCoord[1]"), varying_1f ("gl_TexCoord[2]"), varying_1f ("gl_TexCoord[3]"), |
| 148 |
|
|
varying_1f ("gl_TexCoord[4]"), varying_1f ("gl_TexCoord[5]"), varying_1f ("gl_TexCoord[6]"), varying_1f ("gl_TexCoord[7]"), |
| 149 |
root |
1.11 |
}; |
| 150 |
|
|
varying_2f vin::texcoord_2f[8] = |
| 151 |
|
|
{ |
| 152 |
root |
1.13 |
varying_2f ("gl_TexCoord[0]"), varying_2f ("gl_TexCoord[1]"), varying_2f ("gl_TexCoord[2]"), varying_2f ("gl_TexCoord[3]"), |
| 153 |
|
|
varying_2f ("gl_TexCoord[4]"), varying_2f ("gl_TexCoord[5]"), varying_2f ("gl_TexCoord[6]"), varying_2f ("gl_TexCoord[7]"), |
| 154 |
root |
1.11 |
}; |
| 155 |
|
|
varying_3f vin::texcoord_3f[8] = |
| 156 |
|
|
{ |
| 157 |
root |
1.13 |
varying_3f ("gl_TexCoord[0]"), varying_3f ("gl_TexCoord[1]"), varying_3f ("gl_TexCoord[2]"), varying_3f ("gl_TexCoord[3]"), |
| 158 |
|
|
varying_3f ("gl_TexCoord[4]"), varying_3f ("gl_TexCoord[5]"), varying_3f ("gl_TexCoord[6]"), varying_3f ("gl_TexCoord[7]"), |
| 159 |
root |
1.11 |
}; |
| 160 |
|
|
varying_4f vin::texcoord_4f[8] = |
| 161 |
|
|
{ |
| 162 |
root |
1.13 |
varying_4f ("gl_TexCoord[0]"), varying_4f ("gl_TexCoord[1]"), varying_4f ("gl_TexCoord[2]"), varying_4f ("gl_TexCoord[3]"), |
| 163 |
|
|
varying_4f ("gl_TexCoord[4]"), varying_4f ("gl_TexCoord[5]"), varying_4f ("gl_TexCoord[6]"), varying_4f ("gl_TexCoord[7]"), |
| 164 |
root |
1.11 |
}; |
| 165 |
root |
1.9 |
varying_1f vin::psize_1f ("PSIZE"); |
| 166 |
|
|
|
| 167 |
root |
1.13 |
glvar vout::position ("gl_Position"); |
| 168 |
|
|
glvar vout::point_size ("gl_PointSize"); |
| 169 |
|
|
glvar vout::clip_vertex ("gl_ClipVertex"); |
| 170 |
|
|
glvar vout::front_color ("gl_FontColor"); |
| 171 |
|
|
glvar vout::back_color ("gl_BackColor"); |
| 172 |
|
|
glvar vout::front_secondary_color ("gl_FrontSecondaryColor"); |
| 173 |
|
|
glvar vout::back_secondary_color ("gl_BackSecondaryColor"); |
| 174 |
|
|
glvar vout::texcoord[8] = |
| 175 |
|
|
{ |
| 176 |
|
|
glvar ("gl_TexCoord[0]"), glvar ("gl_TexCoord[1]"), glvar ("gl_TexCoord[2]"), glvar ("gl_TexCoord[3]"), |
| 177 |
|
|
glvar ("gl_TexCoord[4]"), glvar ("gl_TexCoord[5]"), glvar ("gl_TexCoord[6]"), glvar ("gl_TexCoord[7]"), |
| 178 |
|
|
}; |
| 179 |
|
|
glvar vout::fog_frag_coord ("gl_FogFragCoord"); |
| 180 |
|
|
|
| 181 |
|
|
glvar fin::frag_coord ("gl_FragCoord"); |
| 182 |
|
|
glvar fin::color ("gl_Color"); |
| 183 |
|
|
glvar fin::secondary_color ("gl_SecondaryColor"); |
| 184 |
|
|
glvar fin::texcoord[8] = |
| 185 |
|
|
{ |
| 186 |
|
|
glvar ("gl_TexCoord[0]"), glvar ("gl_TexCoord[1]"), glvar ("gl_TexCoord[2]"), glvar ("gl_TexCoord[3]"), |
| 187 |
|
|
glvar ("gl_TexCoord[4]"), glvar ("gl_TexCoord[5]"), glvar ("gl_TexCoord[6]"), glvar ("gl_TexCoord[7]"), |
| 188 |
|
|
}; |
| 189 |
|
|
glvar fin::fog_frag_coord ("gl_FogFragCoord"); |
| 190 |
root |
1.9 |
|
| 191 |
root |
1.13 |
glvar fout::frag_color ("gl_FragColor"); |
| 192 |
|
|
glvar fout::frag_depth ("gl_FragDepth"); |
| 193 |
|
|
glvar fout::frag_data[2] = { glvar ("gl_FragData[0]"), glvar ("gl_FragData[1]") }; |
| 194 |
root |
1.9 |
|
| 195 |
root |
1.13 |
#if 0 |
| 196 |
root |
1.12 |
varying_4f fin::position_4f ("gl_Position"); |
| 197 |
|
|
varying_4f fin::color_4f ("gl_Color"); |
| 198 |
|
|
varying_4f fin::color2_4f ("gl_SecondaryColor"); |
| 199 |
root |
1.11 |
varying_4f fin::texcoord_4f[8] = |
| 200 |
|
|
{ |
| 201 |
root |
1.12 |
varying_4f ("gl_TexCoord[0]"), varying_4f ("gl_TexCoord[1]"), varying_4f ("gl_TexCoord[2]"), varying_4f ("gl_TexCoord[3]"), |
| 202 |
|
|
varying_4f ("gl_TexCoord[4]"), varying_4f ("gl_TexCoord[5]"), varying_4f ("gl_TexCoord[6]"), varying_4f ("gl_TexCoord[7]"), |
| 203 |
root |
1.11 |
}; |
| 204 |
root |
1.13 |
#endif |
| 205 |
root |
1.9 |
|
| 206 |
|
|
struct fout fout; |
| 207 |
|
|
|
| 208 |
root |
1.13 |
#if 0 |
| 209 |
root |
1.12 |
varying_4f fout::color_4f ("gl_FragColor"); |
| 210 |
|
|
varying_1f fout::depth_1f ("gl_FragDepth"); |
| 211 |
root |
1.13 |
#endif |
| 212 |
|
|
|
| 213 |
|
|
//////////////////////////////////////////////////////////////////////////// |
| 214 |
root |
1.9 |
|
| 215 |
root |
1.13 |
shader_object_i::shader_object_i (GLenum type) |
| 216 |
|
|
: type (type) |
| 217 |
root |
1.9 |
{ |
| 218 |
root |
1.13 |
id = glCreateShaderObjectARB (type); |
| 219 |
root |
1.9 |
} |
| 220 |
|
|
|
| 221 |
root |
1.13 |
shader_object_i::~shader_object_i () |
| 222 |
root |
1.9 |
{ |
| 223 |
root |
1.13 |
glDeleteObjectARB (id); |
| 224 |
root |
1.9 |
} |
| 225 |
|
|
|
| 226 |
root |
1.13 |
string shader_object_i::source () |
| 227 |
root |
1.9 |
{ |
| 228 |
|
|
shader_builder b; |
| 229 |
|
|
build (b); |
| 230 |
|
|
ostringstream os; |
| 231 |
|
|
|
| 232 |
root |
1.12 |
for (vector<uniform>::iterator i = b.refs.begin (); i != b.refs.end (); i++) |
| 233 |
root |
1.9 |
{ |
| 234 |
|
|
(*i)->build_decl (os); |
| 235 |
root |
1.12 |
os << ";\n"; |
| 236 |
root |
1.9 |
} |
| 237 |
|
|
|
| 238 |
root |
1.12 |
#if 0 |
| 239 |
|
|
// not neccessary right now, as GLSL is rich on predefinitions |
| 240 |
|
|
for (vector<var>::iterator i = b.streams.begin (); i != b.streams.end (); i++) |
| 241 |
root |
1.9 |
{ |
| 242 |
root |
1.12 |
if (vout.is (*i) || fout.is (*i)) |
| 243 |
|
|
os << "varying "; |
| 244 |
|
|
else if (vin.is (*i)) |
| 245 |
|
|
os << "attribute "; |
| 246 |
|
|
|
| 247 |
root |
1.9 |
(*i)->build_decl (os); |
| 248 |
root |
1.12 |
os << ";\n"; |
| 249 |
root |
1.9 |
} |
| 250 |
root |
1.12 |
#endif |
| 251 |
root |
1.9 |
|
| 252 |
root |
1.13 |
os << "\nvoid main (void)\n{\n"; |
| 253 |
root |
1.9 |
|
| 254 |
|
|
for (vector<var>::iterator i = b.temps.begin (); i != b.temps.end (); i++) |
| 255 |
|
|
{ |
| 256 |
root |
1.13 |
os << " "; |
| 257 |
root |
1.9 |
(*i)->build_decl (os); |
| 258 |
|
|
os << ";\n"; |
| 259 |
|
|
} |
| 260 |
|
|
|
| 261 |
|
|
os << "\n"; |
| 262 |
|
|
os << b.source.str (); |
| 263 |
root |
1.13 |
os << "}\n"; |
| 264 |
|
|
|
| 265 |
|
|
return os.str (); |
| 266 |
|
|
} |
| 267 |
|
|
|
| 268 |
|
|
void shader_object_i::compile () |
| 269 |
|
|
{ |
| 270 |
|
|
string src = source (); |
| 271 |
|
|
const char *sptr = src.data (); |
| 272 |
|
|
const int slen = src.size (); |
| 273 |
|
|
|
| 274 |
|
|
printf ("SOURCE<%s>\n", src.c_str ()); |
| 275 |
root |
1.9 |
|
| 276 |
root |
1.13 |
glShaderSourceARB (id, 1, &sptr, &slen); |
| 277 |
|
|
glCompileShaderARB (id); |
| 278 |
root |
1.9 |
|
| 279 |
root |
1.13 |
GLint compiled; |
| 280 |
|
|
glGetObjectParameterivARB (id, GL_OBJECT_COMPILE_STATUS_ARB, &compiled); |
| 281 |
|
|
|
| 282 |
|
|
if (!compiled) |
| 283 |
|
|
{ |
| 284 |
|
|
char infolog[8192]; |
| 285 |
|
|
glGetInfoLogARB (id, 8192, NULL, infolog); |
| 286 |
|
|
printf ("INFOLOG<%s>\n", infolog); |
| 287 |
|
|
abort (); |
| 288 |
|
|
} |
| 289 |
root |
1.9 |
} |
| 290 |
|
|
|
| 291 |
|
|
void debdebdebdebug ()//D |
| 292 |
|
|
{ |
| 293 |
root |
1.13 |
fragment_shader p; |
| 294 |
root |
1.11 |
temp_4f t1, t2; |
| 295 |
root |
1.12 |
sampler_2d s2d (1); |
| 296 |
root |
1.9 |
|
| 297 |
root |
1.13 |
//p << t2 << " = texture2D (" << s2d << ", " << vin.position_4f << ".xy)"; |
| 298 |
|
|
//p << t1 << " = mul (" << vin.position_4f << "," << mvp << ")"; |
| 299 |
|
|
p << fout.frag_color << " = vec4(1,1,1,0)"; |
| 300 |
root |
1.9 |
|
| 301 |
root |
1.13 |
p->compile (); |
| 302 |
root |
1.9 |
} |
| 303 |
|
|
|
| 304 |
root |
1.8 |
} |
| 305 |
|
|
|
| 306 |
root |
1.1 |
material::~material () |
| 307 |
|
|
{ |
| 308 |
|
|
} |
| 309 |
|
|
|
| 310 |
root |
1.6 |
void |
| 311 |
|
|
simple_material::begin () |
| 312 |
root |
1.1 |
{ |
| 313 |
root |
1.6 |
glMaterialfv (GL_FRONT, GL_DIFFUSE, (GLfloat *) & diffuse); |
| 314 |
|
|
glMaterialfv (GL_FRONT, GL_SPECULAR, (GLfloat *) & specular); |
| 315 |
|
|
glMaterialfv (GL_FRONT, GL_EMISSION, (GLfloat *) & emission); |
| 316 |
|
|
glMaterialf (GL_FRONT, GL_SHININESS, shininess); |
| 317 |
root |
1.1 |
} |
| 318 |
|
|
|
| 319 |
root |
1.6 |
void |
| 320 |
|
|
simple_material::end () |
| 321 |
root |
1.1 |
{ |
| 322 |
|
|
} |
| 323 |
root |
1.6 |
|
| 324 |
|
|
void |
| 325 |
|
|
osama_material::begin () |
| 326 |
root |
1.3 |
{ |
| 327 |
|
|
cgGLEnableProfile (vsh_profile); |
| 328 |
|
|
cgGLEnableProfile (fsh_profile); |
| 329 |
root |
1.6 |
cgGLEnableTextureParameter (g_Texture); |
| 330 |
root |
1.3 |
} |
| 331 |
root |
1.6 |
|
| 332 |
|
|
void |
| 333 |
|
|
osama_material::end () |
| 334 |
root |
1.3 |
{ |
| 335 |
root |
1.6 |
cgGLDisableTextureParameter (g_Texture); |
| 336 |
|
|
// cgGLUnbindProgram (vsh_profile); |
| 337 |
|
|
// cgGLUnbindProgram (fsh_profile); |
| 338 |
root |
1.3 |
cgGLDisableProfile (vsh_profile); |
| 339 |
|
|
cgGLDisableProfile (fsh_profile); |
| 340 |
|
|
} |
| 341 |
root |
1.1 |
|
| 342 |
root |
1.6 |
GLuint |
| 343 |
|
|
texture::load_texture (SDL_Surface * surface, GLfloat * tex2oord) |
| 344 |
root |
1.3 |
{ |
| 345 |
root |
1.4 |
GLuint textur; |
| 346 |
root |
1.3 |
int w, h; |
| 347 |
|
|
SDL_Surface *image; |
| 348 |
|
|
SDL_Rect area; |
| 349 |
|
|
Uint32 saved_flags; |
| 350 |
|
|
Uint8 saved_alpha; |
| 351 |
|
|
|
| 352 |
|
|
/* Use the surface width and height expanded to powers of 2 */ |
| 353 |
|
|
//w = power_of_two (surface->w); |
| 354 |
|
|
//h = power_of_two (surface->h); |
| 355 |
|
|
w = power_of_two (surface->w); |
| 356 |
|
|
h = power_of_two (surface->h); |
| 357 |
root |
1.5 |
tex2oord[0] = 0.0f; /* Min X */ |
| 358 |
|
|
tex2oord[1] = 0.0f; /* Min Y */ |
| 359 |
|
|
tex2oord[2] = (GLfloat) surface->w / w; /* Max X */ |
| 360 |
|
|
tex2oord[3] = (GLfloat) surface->h / h; /* Max Y */ |
| 361 |
root |
1.3 |
|
| 362 |
|
|
image = SDL_CreateRGBSurface (SDL_SWSURFACE, w, h, 32, |
| 363 |
|
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ |
| 364 |
|
|
0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 |
| 365 |
|
|
#else |
| 366 |
|
|
0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF |
| 367 |
|
|
#endif |
| 368 |
|
|
); |
| 369 |
root |
1.6 |
|
| 370 |
root |
1.3 |
if (image == NULL) |
| 371 |
root |
1.6 |
return 0; |
| 372 |
root |
1.3 |
|
| 373 |
|
|
/* Save the alpha blending attributes */ |
| 374 |
|
|
saved_flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK); |
| 375 |
|
|
saved_alpha = surface->format->alpha; |
| 376 |
|
|
if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) |
| 377 |
root |
1.6 |
SDL_SetAlpha (surface, 0, 0); |
| 378 |
root |
1.3 |
|
| 379 |
|
|
/* Copy the surface into the GL texture image */ |
| 380 |
|
|
area.x = 0; |
| 381 |
|
|
area.y = 0; |
| 382 |
|
|
area.w = surface->w; |
| 383 |
|
|
area.h = surface->h; |
| 384 |
|
|
SDL_BlitSurface (surface, &area, image, &area); |
| 385 |
|
|
|
| 386 |
|
|
/* Restore the alpha blending attributes */ |
| 387 |
|
|
if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) |
| 388 |
root |
1.6 |
SDL_SetAlpha (surface, saved_flags, saved_alpha); |
| 389 |
root |
1.3 |
|
| 390 |
|
|
/* Create an OpenGL texture for the image */ |
| 391 |
root |
1.4 |
glGenTextures (1, &textur); |
| 392 |
|
|
glBindTexture (GL_TEXTURE_2D, textur); |
| 393 |
root |
1.6 |
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 394 |
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 395 |
root |
1.7 |
glTexParameteri (GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); // GENERATE_MIPMAP_SGIS |
| 396 |
root |
1.3 |
glTexImage2D (GL_TEXTURE_2D, |
| 397 |
|
|
0, |
| 398 |
|
|
GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels); |
| 399 |
|
|
SDL_FreeSurface (image); /* No longer needed */ |
| 400 |
|
|
|
| 401 |
root |
1.4 |
return textur; |
| 402 |
root |
1.3 |
} |
| 403 |
|
|
|
| 404 |
root |
1.6 |
CGcontext cgc; |
| 405 |
root |
1.3 |
|
| 406 |
root |
1.6 |
void |
| 407 |
|
|
init_shaders () |
| 408 |
|
|
{ |
| 409 |
root |
1.3 |
cgc = cgCreateContext (); |
| 410 |
|
|
} |
| 411 |
root |
1.8 |
|