Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


#Actual__SKYe

Posted 27 January 2013 - 07:54 AM

Yes it generates them.Here's a sample code i use

 

//Up to this point you should have an array with the texture data. I don't know if the SDL_surface works the same
//Also the var image is a GLuint variable that holds a texture ID

    //Generate a GL texture
    glGenTextures(1, &image);

    //Bind GL texture
    glBindTexture(GL_TEXTURE_2D, image);

    //Sets wrapping style
    //I use GL_REPEAT here, but you can use GL_CLAMP_TO_EDGE, GL_CLAMP is deprecated
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

      //Sets mag / min filters
      //The TF_NO_FILTER, etc are just enums i made for selecting the filter
      switch(this->filter)
      {

      case TF_NO_FILTER:
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
          break;

      case TF_BILINEAR:
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
          break;

      //The this->mipmapMaxLevel is just the maximum level of mipmap to create
      //If it is 4, 4 levels of mipmaps will be created
      case TF_BILINEAR_MIPMAP:
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, this->mipmapMaxLevel);
          break;

      case TF_TRILINEAR:
          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_TEXTURE_BASE_LEVEL, 0);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, this->mipmapMaxLevel);
          break;

      }

    //VAR: The image format
    //You should ignore this, since your texture may have a different data format
    uint32 format = 0;

      if(imageFormat == 0)
      format = GL_RGB;
      else if(imageFormat == 1)
      format = GL_RGBA;

    //Build the texture
    glTexImage2D(GL_TEXTURE_2D,
                 0,
                 GL_RGBA,     //This is the internal format in which OpenGL will store the texture
                 pData.width,  //Your image's width
                 pData.height, //Your image's height
                 0,
                 format,           //Your texture's data format (GL_RGB, GL_RGBA, etc)
                 GL_UNSIGNED_BYTE,  //The size of each color component
                 &imageData[0]);  //A pointer to your texture data (my was imageData)

      //Create mipmaps
      //Again only call this if you're creating mipmaps
      switch (this->filter)
      {

      case TF_BILINEAR_MIPMAP:
      case TF_TRILINEAR:
          glGenerateMipmap(GL_TEXTURE_2D);
          break;

      }

    //Cleanup here...

 

 

I don't know why your code sometimes don't work though...

Also, you are using anisotropic filtering, but i've never used that, so this code might not be exactly what you need.

 

Hope it helps.


#2__SKYe

Posted 27 January 2013 - 07:44 AM

Yes it generates them.Here's a sample code i use
//Up to this point you should have an array with the texture data. I don't know if the SDL_surface works the same    //Also the var image is a GLuint variable that holds a texture ID    //Generate a GL texture    glGenTextures(1, &image);    //Bind GL texture    glBindTexture(GL_TEXTURE_2D, image);    //Sets wrapping style    //I use GL_REPEAT here, but you can use GL_CLAMP_TO_EDGE, GL_CLAMP is deprecated    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);      //Sets mag / min filters      //The TF_NO_FILTER, etc are just enums i made for selecting the filter      switch(this->filter)      {      case TF_NO_FILTER:          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);          break;      case TF_BILINEAR:          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);          break;      //The this->mipmapMaxLevel var in the next 2 filters sets the maximum level for creating mipmaps, so if      //it is 4, 4 levels of mipmap will be created      //Note it should only be set when you're creating mipmaps      case TF_BILINEAR_MIPMAP:          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, this->mipmapMaxLevel);          break;      case TF_TRILINEAR:          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_TEXTURE_BASE_LEVEL, 0);          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, this->mipmapMaxLevel);          break;      }    //VAR: The image format    //You should ignore this, i use this to select the texture data format    //This value will depend of the kind of texture you're using    uint32 format = 0;      if(imageFormat == 0)      format = GL_RGB;      else if(imageFormat == 1)      format = GL_RGBA;    //Build the texture    glTexImage2D(GL_TEXTURE_2D,                 0,                 GL_RGBA,      //This is the internal format that OpenGL will store the texture data                 pData.width,   //Your image's width                 pData.height,  //Your image's height                 0,                 format,            //This is the format of the texture data in the array you provide in the last argument                 GL_UNSIGNED_BYTE, //The type of each color element, since it's using RGBA here, each element is an unsigned byte                 &imageData[0]);  //This is a pointer to the 1st element of the texture data array      //Create mipmaps      //Again, only call this if you are using mipmaps      switch (this->filter)      {      case TF_BILINEAR_MIPMAP:      case TF_TRILINEAR:          glGenerateMipmap(GL_TEXTURE_2D);          break;      }    //Cleanup here...

I don't know why your code sometimes don't work though...

Also, you are using anisotropic filtering, but i've never used that, so this code might not be exactly what you need.
Hope it helps.

#1__SKYe

Posted 27 January 2013 - 07:40 AM

Yes it generates them.Here's a sample code i use

    //Up to this point you should have an array with the texture data. I don't know if the SDL_surface works the same
    //Also the var image is a GLuint variable that holds a texture ID

    //Generate a GL texture
    glGenTextures(1, &image);

    //Bind GL texture
    glBindTexture(GL_TEXTURE_2D, image);

    //Sets wrapping style
    //I use GL_REPEAT here, but you can use GL_CLAMP_TO_EDGE, GL_CLAMP is deprecated
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

      //Sets mag / min filters
      //The TF_NO_FILTER, etc are just enums i made for selecting the filter
      switch(this->filter)
      {

      case TF_NO_FILTER:
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
          break;

      case TF_BILINEAR:
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
          break;

      //The this->mipmapMaxLevel var in the next 2 filters sets the maximum level for creating mipmaps, so if
      //it is 4, 4 levels of mipmap will be created
      //Note it should only be set when you're creating mipmaps
      case TF_BILINEAR_MIPMAP:
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, this->mipmapMaxLevel);
          break;

      case TF_TRILINEAR:
          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_TEXTURE_BASE_LEVEL, 0);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, this->mipmapMaxLevel);
          break;

      }

    //VAR: The image format

    //You should ignore this, i use this to select the texture data format

    //This value will depend of the kind of texture you're using
    uint32 format = 0;

      if(imageFormat == 0)
      format = GL_RGB;
      else if(imageFormat == 1)
      format = GL_RGBA;

    //Build the texture
    glTexImage2D(GL_TEXTURE_2D,
                 0,
                 GL_RGBA,      //This is the internal format that OpenGL will store the texture data
                 pData.width,   //Your image's width
                 pData.height,  //Your image's height
                 0,
                 format,            //This is the format of the texture data in the array you provide in the last argument
                 GL_UNSIGNED_BYTE, //The type of each color element, since it's using RGBA here, each element is an unsigned byte
                 &imageData[0]);  //This is a pointer to the 1st element of the texture data array

      //Create mipmaps
      //Again, only call this if you are using mipmaps
      switch (this->filter)
      {

      case TF_BILINEAR_MIPMAP:
      case TF_TRILINEAR:
          glGenerateMipmap(GL_TEXTURE_2D);
          break;

      }

    //Cleanup here...

 

Hope it helps.


PARTNERS