int main(int argc, char **argv) {
	char serialport[256];
    int n;

    if (argc==1) {
        exit(EXIT_SUCCESS);
    }

    // Parse options from the command line.
    int option_index = 0, opt;
    static struct option loptions[] = {
    	{"port", required_argument, 0, 'p'},		// Command line for setting port: -p /dev/tty.usbmodem####
	    {"delay", required_argument, 0, 'd'}		// Command line for zero delay: -d 0
	};

    while(1) {
    	opt = getopt_long(argc, argv, "hp:b:s:rn:d:", loptions, &option_index);
    	if (opt==-1) break;
    	switch (opt) {
			case '0': break;
	        case 'd':
	            n = strtol(optarg,NULL,10);
	            usleep(n * 1000); 						// Delay (sleep in milliseconds).
	            break;
	        case 'p':
	            strcpy(serialport,optarg);
	            fd = serialport_init(optarg, baudrate);
	            if(fd==-1) return -1;
	            break;
    	}
    }
	
	ep = engOpen(NULL);
	cppVisualSamples = mxCreateDoubleMatrix(numberOfSamples, 1, mxREAL);
	cppTimingSamples = mxCreateDoubleMatrix(numberOfSamples, 1, mxREAL);
	dataSetVisual = mxGetPr(cppVisualSamples);
	dataSetTiming = mxGetPr(cppTimingSamples);
    glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize(window_width,window_height);					// Window size (in pixels).
	glutInitWindowPosition(100,100);								// Window position (from upper left).
	glutCreateWindow("Torquometer Visual Field");					// Window title.
	init();
	glutKeyboardFunc(myKeyboardFunc);								// Handles "normal" ascii symbols (letters).
	glutSpecialFunc(mySpecialKeyFunc);								// Handles "special" keyboard keys (up, down).
	glutDisplayFunc(display);										// Default display mode.
	glutIdleFunc(idleDisplay);											// Used with glutSwapBuffers();
	glEnable(GL_DEPTH_TEST);
	//glEnable(GL_TEXTURE_2D);
	makeCheckImage();												// Generates the gradient pattern in the background.
	glGenTextures(1, &texName);
	glBindTexture(GL_TEXTURE_2D, texName);
	//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth, checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage);
	glutMainLoop();
}
Exemplo n.º 2
0
static void init(void)
{    
   glClearColor (0.0, 0.0, 0.0, 0.0);
   glShadeModel(GL_FLAT);
   makeCheckImage();
   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
}
void init(void)
{    
        GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
        GLfloat mat_shininess[] = { 50.0 };

        glClearColor (0.0, 0.0, 0.0, 0.0);
        glShadeModel(GL_FLAT);
        glEnable(GL_DEPTH_TEST);
        glDepthFunc(GL_LEQUAL);

        /* texture stuff */

        /* fill in checkimage array*/
        makeCheckImage();
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

        /* generate '1' texture and return the ID in address starting at &texName*/
        glGenTextures(1, &texName);

        /* set the current texture to texture ID in texName*/
        glBindTexture(GL_TEXTURE_2D, texName); 

        /* wrap the texture around the s- and t-dimension*/
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

        /* if texture is too small or too big for the surface,
         * magnify or minify it by using the texel coordinate 
         * nearest the pixel to be colored.
         */
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
                                   GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                                   GL_NEAREST);

        /* apply the checkimage array to the current texture*/
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth,
                                checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 
                                checkImage);

        /* lighting stuff */
        glShadeModel (GL_SMOOTH);

        /* specular highlights have color 'mat_specular'*/
        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);

        /* shininess ('N') = mat_shininess*/
        glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);

        glEnable(GL_LIGHTING);  /* enable lighting */
        glEnable(GL_LIGHT0);    /* enable light0 */

	/* quadratic stuff */
	quadratic=gluNewQuadric();	
	gluQuadricNormals(quadratic, GLU_SMOOTH);
	gluQuadricTexture(quadratic, GL_TRUE);	

	/* normalize all normal vectors for lighting and shading */
	glEnable(GL_NORMALIZE);
}
Exemplo n.º 4
0
void CDrawPixels8_3::init()
{
	CLearnOpenGLBase::init();

	makeCheckImage();
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
}
Exemplo n.º 5
0
void init(void)
{
    glClearColor (0.0, 0.0, 0.0, 0.0);
    glShadeModel(GL_FLAT);
    glEnable(GL_DEPTH_TEST);

    makeCheckImage();
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

#ifdef GL_VERSION_1_1
    glGenTextures(1, &texName);
    glBindTexture(GL_TEXTURE_2D, texName);
#endif

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
#ifdef GL_VERSION_1_1
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth, checkImageHeight,
                 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage);
#else
    glTexImage2D(GL_TEXTURE_2D, 0, 4, checkImageWidth, checkImageHeight,
                 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage);
#endif
}
Exemplo n.º 6
0
void Sample_9_3::initGL()
{
	glPushAttrib(GL_ALL_ATTRIB_BITS);
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glShadeModel (GL_FLAT);
	glEnable(GL_DEPTH_TEST);

	glPushClientAttrib(GL_ALL_CLIENT_ATTRIB_BITS);
	glPixelStorei (GL_UNPACK_ALIGNMENT, 1);

	makeCheckImage();

	glBindTexture(GL_TEXTURE_2D, m_texName);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth, checkImageHeight,
			0, GL_RGBA, GL_UNSIGNED_BYTE, m_checkImage);
	if (m_drawSub)
		glTexSubImage2D(GL_TEXTURE_2D,0,12,44,subImageWidth,subImageHeight,
				GL_RGBA,GL_UNSIGNED_BYTE,m_subImage);


	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnable(GL_TEXTURE_2D);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
}
Exemplo n.º 7
0
void init(void)
{
  makeCheckImage();
  generateCylinder(&cylinder);
  generatePerFaceNormals(&cylinder);
  generatePerVertexNormals(true, &cylinder, 30);
}
Exemplo n.º 8
0
static void pinit(antmazestruct *mp) 
{
  glClearDepth(1.0);
  glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
  glLightfv(GL_LIGHT0, GL_POSITION, position0);
  glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
  glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
  glLightfv(GL_LIGHT1, GL_POSITION, position1);

  glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05);
  glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.001);
  glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1);

  glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.05);
  glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.001);
  glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0.1);


/*   glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); */
/*   glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); */
  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHT1);
  glEnable(GL_NORMALIZE);
  glFrontFace(GL_CCW);
  glCullFace(GL_BACK);
  
  /* antmaze */
  glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess);
  glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular);

  glShadeModel(GL_SMOOTH);
  glEnable(GL_DEPTH_TEST);
  glDisable(GL_TEXTURE_2D);

  /* setup textures */
  makeCheckImage(mp);
  makeBrushedImage(mp);

  build_board(mp, 0);
  build_board(mp, 1);

/*   makeCheckImage(); */
/*   glPixelStorei(GL_UNPACK_ALIGNMENT, 1); */
/*   glTexImage2D(GL_TEXTURE_2D, 0, 3, checkImageWidth,  */
/* 	       checkImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, checkers); */
/*   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); */
/*   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); */

/*   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); */
/*   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); */
/*   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); */
  glEnable(GL_TEXTURE_2D);
    
/*   glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess); */
/*   glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular); */
}
Exemplo n.º 9
0
void init(void) {
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glShadeModel(GL_FLAT);
    makeCheckImage();
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    glHistogram(GL_HISTOGRAM, histogram_size, GL_RGB, GL_FALSE);
    glEnable(GL_HISTOGRAM);
}
Exemplo n.º 10
0
int main(int argc, char** argv){

    srand(time(NULL));
    makeCheckImage();
    makemyImage();
    glutInit(&argc, argv);
    drawTex();
    return 0;
}
Exemplo n.º 11
0
void init(void) {
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glShadeModel(GL_FLAT);
    makeCheckImage();
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    
    bufferSize = imageWidth * imageHeight * numComponents * sizeof(GLfloat);
    glGenBuffers(1, &pixelBuffer);
    glBindBuffer(GL_PIXEL_PACK_BUFFER, pixelBuffer);
    glBufferData(GL_PIXEL_PACK_BUFFER, bufferSize, NULL, GL_STREAM_READ);
}
Exemplo n.º 12
0
static void init(void)
{    
   static const GLfloat v[] = {
       -2.0, -1.0, 0.0,
       -2.0, 1.0, 0.0,
       0.0, -1.0, 0.0,
       0.0, 1.0, 0.0,

       1.0, -1.0, 0.0,
       1.0, 1.0, 0.0,
       2.41421f, -1.0, -1.41421f,
       2.41421f, 1.0, -1.41421f,
   };
   static const GLfloat t[] = {
       0.0, 0.0,
       0.0, 3.0,
       3.0, 0.0,
       3.0, 3.0,

       0.0, 0.0,
       0.0, 3.0,
       3.0, 0.0,
       3.0, 3.0,
   };

   glClearColor (0.0, 0.0, 0.0, 0.0);
   glShadeModel(GL_FLAT);
   glEnable(GL_DEPTH_TEST);

   makeCheckImage();
   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

   glGenTextures(1, &texName);
   glBindTexture(GL_TEXTURE_2D, texName);

   glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
   glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
   glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
   glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth, checkImageHeight, 
                0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage);
#if 0
   glTexImage2D(GL_TEXTURE_2D, 0, 4, checkImageWidth, checkImageHeight, 
                0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage);
#endif
   glVertexPointer(3, GL_FLOAT, 0, v);
   glTexCoordPointer(2, GL_FLOAT, 0, t);

   glEnableClientState(GL_VERTEX_ARRAY);
   glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
Exemplo n.º 13
0
void init(void)
{
   /* Report the number of available texture units */

   GLint textureUnits,vertexUnits,fragmentUnits,combinedUnits;
   GLint vertexAttribs;

   glGetIntegerv(GL_MAX_TEXTURE_UNITS,               &textureUnits);  
   glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS,         &fragmentUnits);
   glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS,  &vertexUnits);
   glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,&combinedUnits);

   printf("%d texture units, %d fragment, %d vertex and %d combined texture units.\n",textureUnits,fragmentUnits,vertexUnits,combinedUnits);

   glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &vertexAttribs);

   printf("%u vertex attributes.\n",vertexAttribs);

   /* Initialize OpenGL */

   glClearColor (0.0, 1.0, 0.0, 0.0);
   glShadeModel(GL_FLAT);
   glEnable(GL_DEPTH_TEST);

#ifdef USE_UNIT
   glActiveTexture(USE_UNIT);
#endif

   makeCheckImage();
   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

#if USE_VERSION_1_1
   glGenTextures(1, &texName);
   glBindTexture(GL_TEXTURE_2D, texName);
#endif

   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
#if USE_VERSION_1_1
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth, checkImageHeight,
                0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage);
#else
   glTexImage2D(GL_TEXTURE_2D, 0, 4, checkImageWidth, checkImageHeight,
                0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage);
#endif
}
Exemplo n.º 14
0
int main(int argc,  char* argv[])
{

    
    makeCheckImage();
    
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE| GLUT_RGB);
    glutInitWindowPosition(160,160);
    glutInitWindowSize(window_width, window_height);
    glutCreateWindow("OpenGL window");
    myViewer.initWithBuffer(buffer,texture_width,texture_height);
    glutReshapeFunc(reshape);
    glutMouseFunc(mouseClick);
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
}
void myinit(void)
{    
    glClearColor (0.0, 0.0, 0.0, 0.0);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    makeCheckImage();
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glTexImage2D(GL_TEXTURE_2D, 0, 4, checkImageWidth, 
	checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 
	&checkImage[0][0][0]);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
    glEnable(GL_TEXTURE_2D);
    glShadeModel(GL_FLAT);
}
Exemplo n.º 16
0
void init()
{
  glClearColor(0.0, 0.0, 0.0, 1.0);

  glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);

  glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
  glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view);

  glMaterialfv(GL_LIGHT0, GL_SPECULAR, mat_specular);
  glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
  glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  glMaterialf(GL_LIGHT0, GL_SHININESS, mat_shininess);
  glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);

  glShadeModel(GL_SMOOTH);  /* enable smooth shading */
  glEnable(GL_LIGHTING);    /* enable lighting */
  glEnable(GL_LIGHT0);      /* enable light 0 */

  glEnable(GL_DEPTH_TEST);

// following are texture mapping part
 // glClearColor(0.0f, 0.0f, 0.0f, 0.5f);        // Black Background
  glEnable ( GL_COLOR_MATERIAL );
  glColorMaterial ( GL_LIGHT0, GL_AMBIENT_AND_DIFFUSE );


  glEnable ( GL_TEXTURE_2D );
  glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 );
 // glGenTextures (1, texture_id);

  image_t   temp_image;


  glBindTexture ( GL_TEXTURE_2D, texture_id[MOUNTAIN_TEXTURE] );
  tgaLoad  ( "mountains-hero.tga", &temp_image, TGA_FREE | TGA_LOW_QUALITY );


//try to load a second picture

  glPixelStorei ( GL_UNPACK_ALIGNMENT, 2);
 // glGenTextures (2, texture_id);

  image_t   temp_image2;

  glBindTexture ( GL_TEXTURE_2D, texture_id[CLOUD_TEXTURE] );
  tgaLoad  ( "atmosphere_clouds.tga", &temp_image2, TGA_FREE | TGA_LOW_QUALITY );

  //try to load a third texture
  glPixelStorei ( GL_UNPACK_ALIGNMENT, 3 );
  glGenTextures (3, texture_id);

  image_t   temp_image3;


  glBindTexture ( GL_TEXTURE_2D, texture_id[CHECKBOARD_TEXTURE] );
  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_WRAP_S, GL_CLAMP_TO_EDGE);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

   glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
  tgaLoad  ( "color_checkboard.tga", &temp_image3, TGA_FREE | TGA_LOW_QUALITY );


// a flat image
   glShadeModel(GL_FLAT);

   makeCheckImage();
   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

   glGenTextures(4, &texture_id[3]);
   glBindTexture(GL_TEXTURE_2D, texture_id[3]);

   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, 
                   GL_NEAREST);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 
                   GL_NEAREST);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth, 
                checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 
                checkImage);

   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glEnable(GL_TEXTURE_2D);
   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
   glBindTexture(GL_TEXTURE_2D, texture_id[3]);

 

  glEnable ( GL_CULL_FACE );


  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
Exemplo n.º 17
0
void loadTexture() {
    Image *image1;
    // allocate space for texture
    image1 = (Image *) malloc(sizeof(Image));
    if (image1 == NULL) {
        printf("Error allocating space for image");
        exit(0);
    }
    if (!ImageLoad("media/road1.bmp", image1)) {
        exit(1);
    }
    // if(image1 == NULL){
    //     printf("Image was not returned from loadTexture\n");
    //     exit(0);
    // }
    makeCheckImage();
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    // Create Texture
    glGenTextures(1, &texture[0]);
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //scale linearly when image bigger than texture
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); //scale linearly when image smalled than texture
    glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->sizeX, image1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image1->data);

    if (!ImageLoad("media/grass02.bmp", image1)) {
        exit(1);
    }
    // if(image1 == NULL){
    //     printf("Image was not returned from loadTexture\n");
    //     exit(0);
    // }
    makeCheckImage();
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    // Create Texture
    glGenTextures(2, &texture[1]);
    glBindTexture(GL_TEXTURE_2D, texture[1]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //scale linearly when image bigger than texture
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); //scale linearly when image smalled than texture
    glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->sizeX, image1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image1->data);

    if (!ImageLoad("media/night-sky.bmp", image1)) {
        exit(1);
    }
    // if(image1 == NULL){
    //     printf("Image was not returned from loadTexture\n");
    //     exit(0);
    // }
    makeCheckImage();
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    // Create Texture
    glGenTextures(3, &texture[2]);
    glBindTexture(GL_TEXTURE_2D, texture[2]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //scale linearly when image bigger than texture
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); //scale linearly when image smalled than texture
    glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->sizeX, image1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image1->data);

    if (!ImageLoad("media/background02.bmp", image1)) {
        exit(1);
    }
    // if(image1 == NULL){
    //     printf("Image was not returned from loadTexture\n");
    //     exit(0);
    // }
    makeCheckImage();
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    // Create Texture
    glGenTextures(3, &texture[3]);
    glBindTexture(GL_TEXTURE_2D, texture[3]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //scale linearly when image bigger than texture
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); //scale linearly when image smalled than texture
    glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->sizeX, image1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image1->data);

//	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

}