Logo

¡Bienvenido a Stratos!

Acceder

Foros



no veo las texturas

Iniciado por killgates, 06 de Febrero de 2016, 05:27:58 PM

« anterior - próximo »

killgates

Hola de nuevo  :D
Sigo teniendo problemas con las texturas, la pantalla se queda en negro pero responde a los eventos. Si sustituyo las texturas por un color uniforme se ve el objeto 3d.
Mejor pongo el código..:

Éste es el código que carga el fichero de texturas en memoria y luego crea el objeto de textura y vuelca los datos en él..:

    void elemento::CrearTexturas(char FicheroToConvertText[], struct TexturaCabezera *tgaFile){
    //!******* ESTO CREA EL OBJETO DE LA CLASE QUE EXTRAE DATOS DE LA IMAGEN DE TEXTURA **********
       // TargaImage textura; 
        FILE *filePtr;
        unsigned char ucharBad;
        short int sintBad;

        filePtr = fopen(FicheroToConvertText, "rb");
        if (filePtr == NULL)
        {
        exit(1);
        }
        //fseek(filePtr, 0, SEEK_SET);
        std::cout << "\nel fichero de textura a leer es..: " << FicheroToConvertText;
        std::cout << "\nPulse una tecla.." ; getchar();

    // Read the two first bytes we don't need.     Estos dos bits no los necesito..
    fread(&ucharBad, sizeof(unsigned char), 1, filePtr);
    fread(&ucharBad, sizeof(unsigned char), 1, filePtr);
        // Which type of image gets stored in imageTypeCode.

    fread(&tgaFile->imageTypeCode, sizeof(unsigned char), 1, filePtr);   //!Esto lee el tipo de imagen que es la textura
/*
                if (tgaFile->imageTypeCode != 2 && tgaFile->imageTypeCode != 3)
                {
                    fclose(filePtr);
                    return;
                }      //!Sale de la función creartexturas si el tipo de textura está comprimido. ver pagina 178 del libro
*/
    // Read 13 bytes of data we don't need.       Lo mismo de antes .. no los necesito
    fread(&sintBad, sizeof(short int), 1, filePtr);
    fread(&sintBad, sizeof(short int), 1, filePtr);
    fread(&ucharBad, sizeof(unsigned char), 1, filePtr);
    fread(&sintBad, sizeof(short int), 1, filePtr);
    fread(&sintBad, sizeof(short int), 1, filePtr);

        // Read the image's width and height.
        fread(&tgaFile->imageWidth, sizeof(short int), 1, filePtr);
        fread(&tgaFile->imageHeight, sizeof(short int), 1, filePtr);
        // Read the bit depth.
        fread(&tgaFile->bitCount, sizeof(unsigned char), 1, filePtr);

    // Read one byte of data we don't need.
    fread(&ucharBad, sizeof(unsigned char), 1, filePtr);

        long imageSize;
        int colorMode; // Color mode -> 3 = BGR, 4 = BGRA.
        colorMode = tgaFile->bitCount / 8;
        imageSize = tgaFile->imageWidth * tgaFile->imageHeight * colorMode;

        //!esto da dimensión al arreglo imagedata
        tgaFile->imageData = (unsigned char*)malloc(sizeof(unsigned char)*imageSize);
        fread(tgaFile->imageData, sizeof(unsigned char), imageSize, filePtr);

       //!Aquí muestro lo que he leido del fichero ..:
        std::cout << "\nEsto es lo que se ha leido de la cabezera del fichero tga..:";
       // std::cout << "\nidLength..: " << tgaFile.idLength;
        printf("\nimageTypeCode..: %d", tgaFile->imageTypeCode);
        std::cout << "\nLongitud del widht..: " << tgaFile->imageWidth;
        std::cout << "\nLongitud del height..: " << tgaFile->imageHeight;
        printf("\nbitCount..: %d", tgaFile->bitCount);

                        std::cout << "\nAhora se van a mostrar los 20 primeros datos de los datos de imagen..:\n" ;
                        for (int counter = 0; counter < 25; counter++){
                            printf("%d ", tgaFile->imageData[counter]);
                        }
                        getchar();

        fclose(filePtr);


        GLuint firstTexture;
        glGenTextures(1, &firstTexture);



        glBindTexture(GL_TEXTURE_2D, firstTexture);


        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, tgaFile->imageWidth, tgaFile->imageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, tgaFile->imageData);
                    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);



Y esto en el main, que carga los atributos de vértice y dibuja..:

    objeto3d1.CrearTexturas(ficheroText, &tgaFile);        glActiveTexture(GL_TEXTURE0);
//!*****************************************************************************************************
    switch (OpcionMenu) {
    case '2':
        {

        //! Crea la ventana y la inicializa para opengl ******
        OpenGLWindow VentanaOpenGL(hInstance);
        VentanaOpenGL.CrearVentana(1366, 768, 32, 1);
        VentanaOpenGL.IniciaOpenGL();
         objeto3d1.CrearIndices();
        glLoadIdentity();
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        //glEnableClientState(GL_VERTEX_ARRAY);

        // *************************************************
        shader.OpenFiles();
        shader.BorrarLeeFichero();
        shader.leeFichero();
        shader.compila();
        shader.activaShader();

        std::cout << "\nAhora se va a pintar el objeto en pantalla" ;
       // getchar();
        int rotacion = 0;
        shader.envioAtributo(objeto3d1.submodelo[0].vertice, "a_Vertex");
        shader.envioAtributoTextura(objeto3d1.submodelo[0].textura, "coordenadaTextura");
         shader.envioUniformeSamplerText("texture0");

        while (1){
        glLoadIdentity();
        rotacion++; if (rotacion > 360) rotacion = 0;
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        //Ahora dibujo..:
        glTranslatef(0,0,-8);
        glPushMatrix();
        glRotatef(rotacion, 0,1,0);
        shader.cargoMatrices();
        glPopMatrix();
       // for (int modelos = 1 ; modelos > 0 ; modelos-- ){

        glDrawElements(GL_TRIANGLES, objeto3d1.submodelo[0].NumeroIndices, GL_UNSIGNED_INT, objeto3d1.submodelo[0].IndicesVertice);
        //shader.desactivarAtributos();
       // }
        //glPopMatrix();
        for (int retard = 0; retard < 1000000; retard++);
        VentanaOpenGL.ActualizarBuffer();
        VentanaOpenGL.processEvents();
        }


Si me ayudais muchas gracias.. Estoy aprendiendo yo sólo OpengGL y no tengo a nadei a quien preguntar..







Stratos es un servicio gratuito, cuyos costes se cubren en parte con la publicidad.
Por favor, desactiva el bloqueador de anuncios en esta web para ayudar a que siga adelante.
Muchísimas gracias.
Stratos es un servicio gratuito, cuyos costes se cubren en parte con la publicidad.
Por favor, desactiva el bloqueador de anuncios en esta web para ayudar a que siga adelante.
Muchísimas gracias.