Esempio n. 1
0
//*****************************************************************************************************************************
int charger_skybox(int choix) {
    int i;
    MTEX *texture = (MTEX *)malloc(6*sizeof(MTEX));
    textureBox = (GLuint *)malloc(6*sizeof(GLuint));
    glGenTextures(6, textureBox);

    if(choix == DAY) {
        texture[0].filename = "img/light/XN.png";
        texture[1].filename = "img/light/XP.png";
        texture[2].filename = "img/light/YN.png";
        texture[3].filename = "img/light/YP.png";
        texture[4].filename = "img/light/ZN.png";
        texture[5].filename = "img/light/ZP.png";
    }
    else if(choix == NIGHT) {
        texture[0].filename = "img/dark/XN.png";
        texture[1].filename = "img/dark/XP.png";
        texture[2].filename = "img/dark/YN.png";
        texture[3].filename = "img/dark/YP.png";
        texture[4].filename = "img/dark/ZN.png";
        texture[5].filename = "img/dark/ZP.png";
    }
    
    for(i = 0; i < 6; ++i) {
        if(ReadPNGFromFile(&texture[i])) {
            printf("Je n'arrive pas à lire %s\n", texture->filename);
            return -1;
        }
        /* à compléter */
        texture[i].glnum = textureBox[i];
        glBindTexture(GL_TEXTURE_2D, texture[i].glnum);
        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);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
        glTexImage2D(GL_TEXTURE_2D, 0, texture[i].internalFormat,
                      texture[i].width, texture[i].height, 0, texture[i].format,
                      GL_UNSIGNED_BYTE, texture[i].texels);
    }
    free(texture);
    return 0;
}
Esempio n. 2
0
GLuint loadPNGCubeMap (const char *filename, int index) {

  struct gl_texture_t *png_tex = NULL;
  GLuint tex_id = 0;

  png_tex = ReadPNGFromFile (filename);

  if (png_tex && png_tex->texels)
    {

      /* Generate texture */
      glGenTextures (1, &png_tex->id);
      glBindTexture (GL_TEXTURE_CUBE_MAP_POSITIVE_X + index, png_tex->id);

      /* Setup some parameters for texture filters and mipmapping */
      glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
      glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);


     /* glTexImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_X + index, 0, png_tex->internalFormat,
		    png_tex->width, png_tex->height, 0, png_tex->format,
		    GL_UNSIGNED_BYTE, png_tex->texels);*/


      gluBuild2DMipmaps (GL_TEXTURE_CUBE_MAP_POSITIVE_X + index, png_tex->internalFormat,
			 png_tex->width, png_tex->height,
			 png_tex->format, GL_UNSIGNED_BYTE, png_tex->texels);


      tex_id = png_tex->id;

      /* OpenGL has its own copy of texture data */
      free (png_tex->texels);
      free (png_tex);

      printf("%s loaded successfully!\n", filename);
    }

  return tex_id;
}