elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Los 10 CVE más críticos (peligrosos) de 2020


  Mostrar Mensajes
Páginas: [1]
1  Programación / Programación C/C++ / Re: Insertar imágenes en C con Open GL en: 6 Marzo 2012, 16:36 pm
Aver mirando un tutorial trate de hacer esto pero sigue sin aparecer mi textura, me esta volviendo loco...

#include <stdio.h>
#include <windows.h>
#include "GL/glut.h"

typedef struct // Utilizamos esta estructura
{
GLubyte *imageData;
GLuint bpp;
GLuint width;
GLuint height;
GLuint texID;
} Imagen;
int textura;

void *CargaTGA(char *cancha,int *tam)
{
GLubyte TGAheader[12]={0,0,2,0,0,0,0,0,0,0,0,0};
GLubyte TGAcompare[12];
GLubyte header[6];
GLuint bytesPerPixel;
GLuint imageSize;
GLuint temp,i;
GLuint type=GL_RGBA;
Imagen texture;
GLubyte *aux;
FILE *file = fopen(cancha, "rb");
if (file == NULL)
return NULL;
/* Esto abre y comprueba que es un TGA */
fread(TGAcompare,1,sizeof(TGAcompare),file);
if (memcmp(TGAheader,TGAcompare,sizeof(TGAheader))!=0)
return NULL;

/* Leemos la cabecera*/
fread(header,1,sizeof(header),file);
/* Determinamos el tamaño */
texture.width = header[1] * 256 + header[0];
texture.height = header[3] * 256 + header[2];

/* Vemos las características y comprobamos si son correctas*/
if( texture.width <=0 ||texture.height <=0 ||texture.width >256 ||texture.height !=texture.width ||( header[4]!=32))
{
fclose(file);
return NULL;
}
/* Calculamos la memoria que será necesaria */
texture.bpp = header[4];
bytesPerPixel = texture.bpp/8;
imageSize = texture.width*texture.height*bytesPerPixel;

/* Reservamos memoria */
texture.imageData=(GLubyte *)malloc(imageSize);

/* Cargamos y hacemos alguna comprobaciones */
if( texture.imageData==NULL ||
fread(texture.imageData, 1, imageSize, file)!=imageSize)
{
if(texture.imageData!=NULL)
free(texture.imageData);
fclose(file);
return NULL;
}


/* El TGA viene en formato BGR, lo pasamos a RGB */
for(i=0; i<(GLuint)(imageSize); i+=bytesPerPixel)
{
temp=texture.imageData;
texture.imageData = texture.imageData[i + 2];
texture.imageData[i + 2] = temp;
}
fclose (file);

/* Ahora, cambiamos el orden de las líneas, como si hiciesemosun flip vertical. */
aux=(GLubyte *)malloc(imageSize);
for(i=0; i<texture.height; i++)
memcpy(&aux[imageSize-((i+1)*texture.width*4)],&texture.imageData[i*texture.width*4],texture.width*4);

/* tam devolverá el tamaño */
*tam=texture.width;

/* Liberamos memoria */
free(texture.imageData);

/* Todo fue bien!*/
return aux;

}

int carga_texturas(void) {

Imagen texture;
int tam;
texture.imageData=(char *)CargaTGA("cancha.tga",&tam);if (texture.imageData == NULL) {
return -1;
}

/* Genera una textura, referenciada por el entero textura */
glGenTextures (1, &textura);

/* Esta función indica que será una textura en 2D. Las siguientes funciones hará referncia a esta textura */
glBindTexture (GL_TEXTURE_2D, textura);

/* Aquí ajustamos algunos parámetros de la textura, concretamente los filtros */
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);

/* Con esta función de GLU, creamos un mipmap. Nótese que especificamos el tamaño con tam, que devolvia la función CargaTGA*/
gluBuild2DMipmaps (GL_TEXTURE_2D, 4, tam, tam, GL_RGBA,GL_UNSIGNED_BYTE, texture.imageData);

/* Liberamos la memoria que ya no utilizaremos */
free(texture.imageData);

return 0;
}

      
  void display()
  {
   
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glClear(GL_COLOR_BUFFER_BIT);
    glColor4f(0.0, 0.5, 0.2,0.0);
   glBindTexture(GL_TEXTURE_2D, textura);
    glBegin(GL_POLYGON);
      glTexCoord2f(0.0, 0.0);
        glVertex2f(-0.5, 0.9);
      glTexCoord2f(1.0, 0.0);
      glVertex2f(0.5, 0.9);
      glTexCoord2f(1.0, 1.0);
        glVertex2f(0.5, -0.9);
      glTexCoord2f(0.0, 1.0);
        glVertex2f(-0.5,-0.9);
    glEnd();
    glColor3f(1.0, 1.0, 1.0);
    glTranslatef(0.1,0.1,0);
    glPushMatrix();
    glTranslatef(0.1,0.1,0.1);
    glutSolidSphere(0.02,300,300);
    glPopMatrix();
    glutSolidSphere(0.02,300,300);

   glFlush();
  }

  void init()
  {
    glClearColor(0.000, 0.110, 0.392, 0.0); // JMU Gold

    glColor3f(0.314, 0.314, 0.000); // JMU Purple

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(-1.0, 1.0, -1.0, 1.0);
  }

  int main(int argc, char** argv)
  {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(640, 480);
    glutInitWindowPosition(0, 0);
    glutCreateWindow("Test");
    glutDisplayFunc(display);
    init();
    glutMainLoop();
  }

Aver si me pueden ayudar. Saludos.
2  Programación / Programación C/C++ / Re: Insertar imágenes en C con Open GL en: 1 Marzo 2012, 15:24 pm
Buenas acabo de ver el post que me pasaste y sigo con una duda muy grande. Cuando le paso el archivo? por que es como si esa parte todo el mundo se la salteara y la verdad que se me complica mucho. Muchos tutoriales me dicen que cargue la imagen en memoria y ninguna de las que hago me funciona. Un abrazo.

Saludos
3  Programación / Programación C/C++ / Re: Insertar imágenes en C con Open GL en: 28 Febrero 2012, 21:26 pm
Muchísimas gracias Man! ya las voy a leer tranquilo y voy a intentar, si tengo alguna duda te consulto. Muchísimas gracias por respodener tan rápido un abrazo.
4  Programación / Programación C/C++ / Insertar imágenes en C con Open GL en: 28 Febrero 2012, 15:51 pm
Hola gente, estoy haciendo un juego tipo pc futbol y la parte programación esta bastante aceptable ya, pero me quise adentrar a la programación Básica y resulta que no puedo poner por ejemplo en un rectángulo una imagen de una cancha de futbol que quiero poner, alguien me puede dar una mano?

Muchas gracias.
5  Programación / Programación C/C++ / Dibujar la onda de un archivo .wav en c. en: 1 Octubre 2011, 04:35 am
Hola estoy haciendo un trabajo final para la Facu, pero tengo el problema de que no se me ocurre como puedo (dibujar la onda) del archvo, cuando digo dibujar, hablo de ver los valores de la onda en cada muestreo. Si alguien me puede dar una mano se agradecería demasiado.
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines