Esempio n. 1
0
//--------------------------------------------------------------
// reload texture image from file
void mgGL33Services::reloadTextureImage(
  mgGL33TextureImage* texture)
{
  CHECK_THREAD();
  glGenTextures(1, &texture->m_handle);

  glBindTexture(GL_TEXTURE_2D, texture->m_handle);
  if (texture->m_filter == MG_TEXTURE_QUALITY)
  {
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  }
  else
  {
    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, mgGL33TextureWrap(texture->m_xWrap));
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mgGL33TextureWrap(texture->m_yWrap));

  int imgWidth, imgHeight;
  BYTE* data;
  mgLoadRGBAImage(texture->m_fileName, imgWidth, imgHeight, texture->m_transparent, data);

  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imgWidth, imgHeight, 0, 
    GL_RGBA, GL_UNSIGNED_BYTE, data);

  delete data;

  texture->m_width = imgWidth;
  texture->m_height = imgHeight;

  glGenerateMipmap(GL_TEXTURE_2D);
}
Esempio n. 2
0
//--------------------------------------------------------------
// load six image files for cubemap texture
GLuint Planet::loadCubeMap(
  const char* xminFile,
  const char* xmaxFile,
  const char* yminFile,
  const char* ymaxFile,
  const char* zminFile,
  const char* zmaxFile)
{
  GLuint handle;
  glGenTextures(1, &handle);

  glBindTexture(GL_TEXTURE_CUBE_MAP, handle);
  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // NEAREST);
  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

  // load the images in the file list into the array
  int arrayWidth = 0;
  int arrayHeight = 0;

  // load XMIN image
  int imgWidth, imgHeight;
  BOOL hasAlpha;
  BYTE* data;
  mgLoadRGBAImage(xminFile, imgWidth, imgHeight, hasAlpha, data);

  arrayWidth = imgWidth;            
  arrayHeight = imgHeight;

  glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 
    arrayWidth, arrayHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

  delete data;

  // load XMAX image 
  mgLoadRGBAImage(xmaxFile, imgWidth, imgHeight, hasAlpha, data);

  if (imgWidth != arrayWidth || imgHeight != arrayHeight)
    throw new mgException("file %s size is (%d by %d), expected (%d by %d)", 
      xmaxFile, imgWidth, imgHeight, arrayWidth, arrayHeight);

  glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 
    arrayWidth, arrayHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

  delete data;

  // load YMIN image 
  mgLoadRGBAImage(yminFile, imgWidth, imgHeight, hasAlpha, data);

  if (imgWidth != arrayWidth || imgHeight != arrayHeight)
    throw new mgException("file %s size is (%d by %d), expected (%d by %d)", 
      (const char*) yminFile, imgWidth, imgHeight, arrayWidth, arrayHeight);

  glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 
    arrayWidth, arrayHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

  delete data;

  // load YMAX image 
  mgLoadRGBAImage(ymaxFile, imgWidth, imgHeight, hasAlpha, data);

  if (imgWidth != arrayWidth || imgHeight != arrayHeight)
    throw new mgException("file %s size is (%d by %d), expected (%d by %d)", 
      (const char*) ymaxFile, imgWidth, imgHeight, arrayWidth, arrayHeight);

  glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 
    arrayWidth, arrayHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

  delete data;

  // load ZMIN image 
  mgLoadRGBAImage(zminFile, imgWidth, imgHeight, hasAlpha, data);

  if (imgWidth != arrayWidth || imgHeight != arrayHeight)
    throw new mgException("file %s size is (%d by %d), expected (%d by %d)", 
      (const char*) zminFile, imgWidth, imgHeight, arrayWidth, arrayHeight);

  glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 
    arrayWidth, arrayHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

  delete data;

  // load ZMAX image 
  mgLoadRGBAImage(zmaxFile, imgWidth, imgHeight, hasAlpha, data);

  if (imgWidth != arrayWidth || imgHeight != arrayHeight)
    throw new mgException("file %s size is (%d by %d), expected (%d by %d)", 
      (const char*) zmaxFile, imgWidth, imgHeight, arrayWidth, arrayHeight);

  glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 
    arrayWidth, arrayHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

  delete data;

  // generate mipmap
  glGenerateMipmap(GL_TEXTURE_CUBE_MAP);

  return handle;
}
Esempio n. 3
0
//--------------------------------------------------------------
// reload texture cube from file list
void mgGL33Services::reloadTextureCube(
  mgGL33TextureCube* texture)
{
  CHECK_THREAD();
  glGenTextures(1, &texture->m_handle);

  glBindTexture(GL_TEXTURE_CUBE_MAP, texture->m_handle);
  if (texture->m_filter == MG_TEXTURE_QUALITY)
  {
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  }
  else
  {
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  }

  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, mgGL33TextureWrap(texture->m_xWrap));
  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, mgGL33TextureWrap(texture->m_yWrap));

  // load the images in the file list into the array
  int arrayWidth = 0;
  int arrayHeight = 0;

  // load XMIN image
  int imgWidth, imgHeight;
  BOOL hasAlpha;
  BYTE* data;
  mgLoadRGBAImage(texture->m_xminImage, imgWidth, imgHeight, hasAlpha, data);

	texture->m_imgTransparent[0] = hasAlpha;
  arrayWidth = imgWidth;            
  arrayHeight = imgHeight;

  glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 
    arrayWidth, arrayHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

  delete data;

  // load XMAX image 
  mgLoadRGBAImage(texture->m_xmaxImage, imgWidth, imgHeight, hasAlpha, data);

  if (imgWidth != arrayWidth || imgHeight != arrayHeight)
    throw new mgErrorMsg("glTextureArray", "fileName,wd,ht,arraywd,arrayht", 
      (const char*) texture->m_xmaxImage, imgWidth, imgHeight, arrayWidth, arrayHeight);

	texture->m_imgTransparent[1] = hasAlpha;

  glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 
    arrayWidth, arrayHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

  delete data;

  // load YMIN image 
  mgLoadRGBAImage(texture->m_yminImage, imgWidth, imgHeight, hasAlpha, data);

  if (imgWidth != arrayWidth || imgHeight != arrayHeight)
    throw new mgErrorMsg("glTextureArray", "fileName,wd,ht,arraywd,arrayht", 
      (const char*) texture->m_yminImage, imgWidth, imgHeight, arrayWidth, arrayHeight);

	texture->m_imgTransparent[2] = hasAlpha;

  glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 
    arrayWidth, arrayHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

  delete data;

  // load YMAX image 
  mgLoadRGBAImage(texture->m_ymaxImage, imgWidth, imgHeight, hasAlpha, data);

  if (imgWidth != arrayWidth || imgHeight != arrayHeight)
    throw new mgErrorMsg("glTextureArray", "fileName,wd,ht,arraywd,arrayht", 
      (const char*) texture->m_ymaxImage, imgWidth, imgHeight, arrayWidth, arrayHeight);

	texture->m_imgTransparent[3] = hasAlpha;

  glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 
    arrayWidth, arrayHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

  delete data;

  // load ZMIN image 
  mgLoadRGBAImage(texture->m_zminImage, imgWidth, imgHeight, hasAlpha, data);

  if (imgWidth != arrayWidth || imgHeight != arrayHeight)
    throw new mgErrorMsg("glTextureArray", "fileName,wd,ht,arraywd,arrayht", 
      (const char*) texture->m_zminImage, imgWidth, imgHeight, arrayWidth, arrayHeight);

	texture->m_imgTransparent[4] = hasAlpha;

  glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 
    arrayWidth, arrayHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

  delete data;

  // load ZMAX image 
  mgLoadRGBAImage(texture->m_zmaxImage, imgWidth, imgHeight, hasAlpha, data);

  if (imgWidth != arrayWidth || imgHeight != arrayHeight)
    throw new mgErrorMsg("glTextureArray", "fileName,wd,ht,arraywd,arrayht", 
      (const char*) texture->m_zmaxImage, imgWidth, imgHeight, arrayWidth, arrayHeight);

	texture->m_imgTransparent[5] = hasAlpha;

  glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 
    arrayWidth, arrayHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

  delete data;

  texture->m_width = arrayWidth;
  texture->m_height = arrayHeight;

  // generate mipmap
  glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
}
Esempio n. 4
0
//--------------------------------------------------------------
// reload texture array from file list
void mgGL33Services::reloadTextureArray(
  mgGL33TextureArray* texture)
{
  CHECK_THREAD();
  glGenTextures(1, &texture->m_handle);

  glBindTexture(GL_TEXTURE_2D_ARRAY, texture->m_handle);
  if (texture->m_filter == MG_TEXTURE_QUALITY)
  {
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  }
  else
  {
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  }

  glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, mgGL33TextureWrap(texture->m_xWrap));
  glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, mgGL33TextureWrap(texture->m_yWrap));

  // load the images in the file list into the array
  int arrayWidth = 0;
  int arrayHeight = 0;
  mgString fileName;
  for (int i = 0; i < texture->m_fileList.length(); i++)
  {
    fileName = texture->m_fileList[i];

    int imgWidth, imgHeight;
    BOOL hasAlpha;
    BYTE* data;
    mgLoadRGBAImage(fileName, imgWidth, imgHeight, hasAlpha, data);

		texture->m_imgTransparent[i] = hasAlpha;

    // with first image, we have size.  create the texture array
    if (i == 0)
    {
      arrayWidth = imgWidth;
      arrayHeight = imgHeight;
      glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA, 
        arrayWidth, arrayHeight, texture->m_fileList.length(), 
        0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
    }
    else
    {
      if (imgWidth != arrayWidth || imgHeight != arrayHeight)
      throw new mgErrorMsg("glTextureArray", "fileName,wd,ht,arraywd,arrayht", 
        (const char*) fileName, imgWidth, imgHeight, arrayWidth, arrayHeight);
    }

    glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 
      0, 0, i, arrayWidth, arrayHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE, data);

    delete data;
  }

  texture->m_width = arrayWidth;
  texture->m_height = arrayHeight;

  glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
}