void
SGTexture::bind()
{
- if (!texture_data) {
+ bool gen = false;
+ if (!texture_id) {
#ifdef GL_VERSION_1_1
glGenTextures(1, &texture_id);
#elif GL_EXT_texture_object
glGenTexturesEXT(1, &texture_id);
#endif
+ gen = true;
}
#ifdef GL_VERSION_1_1
glBindTextureEXT(GL_TEXTURE_2D, texture_id);
#endif
- if (!texture_data) {
+ if (gen) {
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
void
SGTexture::set_pixel(GLuint x, GLuint y, sgVec3 &c)
{
+ if (!texture_data)
+ return;
+
unsigned int pos = (x + y*texture_width)*3;
texture_data[pos] = c[0];
texture_data[pos+1] = c[1];
SGTexture::get_pixel(GLuint x, GLuint y)
{
static sgVec3 c;
+
+ sgSetVec3(c, 0.0, 0.0, 0.0);
+ if (!texture_data)
+ return;
+
unsigned int pos = (x + y*texture_width)*3;
sgSetVec3(c, texture_data[pos], texture_data[pos+1], texture_data[pos+2]);
sgVec3 *get_pixel(GLuint x, GLuint y);
void bind();
- inline void select() {
+ inline void select(bool keep_data = false) {
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB,
texture_width, texture_height, 0,
GL_RGB, GL_UNSIGNED_BYTE, texture_data );
+
+ if (!keep_data) {
+ delete[] texture_data;
+ texture_data = 0;
+ }
}
// Nowhere does it say that resident textures have to be in video memory!