Esempio n. 1
0
	/// set texture pixels
	void GHL_CALL TextureOpenGL::SetData(UInt32 x,UInt32 y,UInt32 w,UInt32 h,const Data* data,UInt32 level) {
		glActiveTexture(GL_TEXTURE0);
		//glClientActiveTexture(GL_TEXTURE0);
		bind();
		glPixelStorei(GL_UNPACK_ALIGNMENT,1);
#ifndef GHL_OPENGLES
		glPixelStorei(GL_UNPACK_ROW_LENGTH,w);
#endif
		if (format_compressed(m_fmt)) {
			glCompressedTexSubImage2D(GL_TEXTURE_2D, level, x, y, w, h, convert_int_format(m_fmt), data->GetSize(), data->GetData());
		} else {
			glTexSubImage2D(GL_TEXTURE_2D, level, x, y, w, h, convert_format(m_fmt), convert_storage(m_fmt), data->GetData());
		}
		glPixelStorei(GL_UNPACK_ALIGNMENT,4);
#ifndef GHL_OPENGLES
		glPixelStorei(GL_UNPACK_ROW_LENGTH,0);
#endif
		m_parent->RestoreTexture();
	}
Esempio n. 2
0
	TextureOpenGL* TextureOpenGL::Create( RenderOpenGL* parent,TextureFormat fmt,UInt32 w,UInt32 h, const Data* data) {
        if (fmt==TEXTURE_FORMAT_UNKNOWN)
            return 0;
        GLuint name = 0;
		glActiveTexture(GL_TEXTURE0);
		glGenTextures(1, &name);
		if (!name) return 0;
		glBindTexture(GL_TEXTURE_2D, name);

		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		if (format_compressed(fmt)) {
			if ( data )
				glCompressedTexImage2D(GL_TEXTURE_2D, 0, convert_int_format(fmt), w, h, 0, data->GetSize(), data->GetData() );
			else {
				glBindTexture(GL_TEXTURE_2D, 0);
				glDeleteTextures(1, &name);
				return 0;
			}
				
		} else {
			glTexImage2D(GL_TEXTURE_2D, 0, convert_int_format(fmt), w, h, 0, convert_format(fmt), convert_storage(fmt), 
						 data ? data->GetData() : 0);
		}
		
		return new TextureOpenGL( name, parent, fmt, w,h );
	}
Esempio n. 3
0
static void setup_state(const char* vtxs, const ALLEGRO_VERTEX_DECL* decl, ALLEGRO_BITMAP* texture)
{
   if(decl) {
      ALLEGRO_VERTEX_ELEMENT* e;
      e = &decl->elements[ALLEGRO_PRIM_POSITION];
      if(e->attribute) {
         int ncoord = 0;
         GLenum type = 0;
         bool normalized;

         glEnableClientState(GL_VERTEX_ARRAY);

         convert_storage(e->storage, &type, &ncoord, &normalized);

         glVertexPointer(ncoord, type, decl->stride, vtxs + e->offset);
      } else {
         glDisableClientState(GL_VERTEX_ARRAY);
      }

      e = &decl->elements[ALLEGRO_PRIM_TEX_COORD];
      if(!e->attribute)
         e = &decl->elements[ALLEGRO_PRIM_TEX_COORD_PIXEL];
      if(texture && e->attribute) {
         int ncoord = 0;
         GLenum type = 0;
         bool normalized;

         glEnableClientState(GL_TEXTURE_COORD_ARRAY);

         convert_storage(e->storage, &type, &ncoord, &normalized);

         glTexCoordPointer(ncoord, type, decl->stride, vtxs + e->offset);
      } else {
         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
      }

      e = &decl->elements[ALLEGRO_PRIM_COLOR_ATTR];
      if(e->attribute) {
         glEnableClientState(GL_COLOR_ARRAY);

         glColorPointer(4, GL_FLOAT, decl->stride, vtxs + e->offset);
      } else {
         glDisableClientState(GL_COLOR_ARRAY);
         glColor4f(1, 1, 1, 1);
      }
   } else {
      const ALLEGRO_VERTEX* vtx = (const ALLEGRO_VERTEX*)vtxs;
   
      glEnableClientState(GL_COLOR_ARRAY);
      glEnableClientState(GL_VERTEX_ARRAY);
      glEnableClientState(GL_TEXTURE_COORD_ARRAY);

      glVertexPointer(3, GL_FLOAT, sizeof(ALLEGRO_VERTEX), &vtx[0].x);
      glColorPointer(4, GL_FLOAT, sizeof(ALLEGRO_VERTEX), &vtx[0].color.r);
      glTexCoordPointer(2, GL_FLOAT, sizeof(ALLEGRO_VERTEX), &vtx[0].u);
   }

   if (texture) {
      GLuint gl_texture = al_get_opengl_texture(texture);
      int true_w, true_h;
      int tex_x, tex_y;
      GLuint current_texture;
      float mat[4][4] = {
         {1,  0,  0, 0},
         {0, -1,  0, 0},
         {0,  0,  1, 0},
         {0,  0,  0, 1}
      };
      int height;

      if (texture->parent)
         height = texture->parent->h;
      else
         height = texture->h;
      
      al_get_opengl_texture_size(texture, &true_w, &true_h);
      al_get_opengl_texture_position(texture, &tex_x, &tex_y);
      
      mat[3][0] = (float)tex_x / true_w;
      mat[3][1] = (float)(height - tex_y) / true_h;
         
      if(decl) {
         if(decl->elements[ALLEGRO_PRIM_TEX_COORD_PIXEL].attribute) {
            mat[0][0] = 1.0f / true_w;
            mat[1][1] = -1.0f / true_h;
         } else {
            mat[0][0] = (float)al_get_bitmap_width(texture) / true_w;
            mat[1][1] = -(float)al_get_bitmap_height(texture) / true_h;
         }
      } else {
         mat[0][0] = 1.0f / true_w;
         mat[1][1] = -1.0f / true_h;
      }

      glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&current_texture);
      if (current_texture != gl_texture) {
         glBindTexture(GL_TEXTURE_2D, gl_texture);
      }

      glMatrixMode(GL_TEXTURE);
      glLoadMatrixf(mat[0]);
      glMatrixMode(GL_MODELVIEW);
   } else {
      glBindTexture(GL_TEXTURE_2D, 0);
   }
}