home *** CD-ROM | disk | FTP | other *** search
/ 3D World 7 (Spanish) / 3DWorld_07.iso / pc / artic / w_prog / ejemplo1.c next >
C/C++ Source or Header  |  1997-06-20  |  3KB  |  111 lines

  1.  
  2. /*  ejemplo1.c
  3.  *  Este programa textura una imagen de bandas de color rojo
  4.  *  y verde sobre dos cuadrados. Se utiliza la opciÛn de texturar
  5.  *  del tipo "clamp", donde la textura se aplica de manera tal que 
  6.  *    si las coordenadas son mayores que 1.0 o menores que 0.0, entonces
  7.  *  toman los valores de 1.0 y 0.0 respectivamente.
  8.  */
  9.  
  10. #include "glos.h"
  11. #include <GL/gl.h>
  12. #include <GL/glu.h>
  13. #include <GL/glaux.h>
  14. void myinit(void);
  15. void CreaImagen(void);
  16. void CALLBACK myReshape(GLsizei w, GLsizei h);
  17. void CALLBACK display(void);
  18. #define AnchoImagen 16         
  19. #define AltoImagen 16
  20. GLubyte ColorImagen[AnchoImagen][AltoImagen][3];
  21.  
  22. void CreaImagen(void)
  23. {    
  24.     int i, j;
  25.     for (i = 0; i < AnchoImagen; i++) {
  26.     for (j = 0; j < AltoImagen; j++) {
  27.       if( i%2){
  28.                 ColorImagen[i][j][0] = 255;
  29.                 ColorImagen[i][j][1] = 0;
  30.                 ColorImagen[i][j][2] = 0;
  31.             }
  32.             else{
  33.                 ColorImagen[i][j][0] =0;
  34.                 ColorImagen[i][j][1] = 255;
  35.                 ColorImagen[i][j][2] = 0;
  36.             }
  37.     }
  38.     }
  39. }
  40.  
  41. void myinit(void)
  42. {    
  43.   glClearColor (0.0, 0.0, 0.0, 0.0);
  44.   glEnable(GL_DEPTH_TEST);
  45.   glDepthFunc(GL_LESS);
  46.  
  47.   CreaImagen();
  48.   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  49.  
  50.     glTexImage2D(GL_TEXTURE_2D, 0, 3, AnchoImagen, 
  51.         AltoImagen, 0, GL_RGB, GL_UNSIGNED_BYTE, 
  52.         &ColorImagen[0][0][0]);
  53.   
  54.   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  55.     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  56.     
  57.   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  58.   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  59.   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  60.   glEnable(GL_TEXTURE_2D);
  61.   glShadeModel(GL_FLAT);
  62. }
  63.  
  64. void CALLBACK display(void)
  65. {
  66.     
  67.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  68.   glBegin(GL_QUADS);
  69.         
  70.     glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 1.0, 0.0);
  71.   glTexCoord2f(0.0, 1.0); glVertex3f(0.0, -1.0, 0.0);
  72.   glTexCoord2f(1.0, 1.0); glVertex3f(-2.0, -1.0, 0.0);
  73.   glTexCoord2f(1.0, 0.0); glVertex3f(-2.0, 1.0, 0.0);
  74.     
  75.     glTexCoord2f(0.0, 0.0); glVertex3f(2.41421, 1.0, -1.41421);
  76.   glTexCoord2f(0.0, 1.0); glVertex3f(2.41421, -1.0, -1.41421);
  77.   glTexCoord2f(1.0, 1.0); glVertex3f(1.0, -1.0, 0.0);
  78.   glTexCoord2f(1.0, 0.0); glVertex3f(1.0, 1.0, 0.0);
  79.     
  80.     glEnd();
  81.   glFlush();
  82. }
  83.  
  84. void CALLBACK myReshape(GLsizei w, GLsizei h)
  85. {
  86.   h = (h == 0) ? 1 : h;
  87.   glViewport(0, 0, w, h);
  88.   glMatrixMode(GL_PROJECTION);
  89.   glLoadIdentity();
  90.   gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 30.0);
  91.   glMatrixMode(GL_MODELVIEW);
  92.   glLoadIdentity();
  93.   glTranslatef(0.0, 0.0, -3.6);
  94. }
  95.  
  96. int main(int argc, char** argv)
  97. {
  98.     auxInitDisplayMode (AUX_SINGLE | AUX_RGB | AUX_DEPTH16);
  99.   auxInitPosition (0, 0, 500, 500);
  100.   auxInitWindow ("Textura de mapping a rayas");
  101.   myinit();
  102.   auxReshapeFunc (myReshape);
  103.   auxMainLoop(display);
  104.   return(0);
  105. }
  106.  
  107.  
  108.  
  109.  
  110.  
  111.