TextureTest.c 2.83 KB
		
		GLfloat Normals[6][3] =
			{{ -1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {1.0, 0.0, 0.0},
			{0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}};
		GLint faces[6][4] =
			{{0, 1, 2, 3}, {3, 2, 6, 7}, {7, 6, 5, 4},
	 		{4, 5, 1, 0}, {5, 6, 2, 1}, {7, 4, 0, 3}};
		GLfloat vertex[8][3] =
			{{-1.0, -1.0, 1.0}, {-1.0, -1.0, -1.0}, {-1.0, 1.0, -1.0},
	 		{-1.0, 1.0, 1.0}, {1.0, -1.0, 1.0}, {1.0, -1.0, -1.0},
	 		{1.0, 1.0, -1.0}, {1.0, 1.0, 1.0}};



void
renderScene(void)
	{
		glEnable(GL_TEXTURE_3D);
		glBindTexture(GL_TEXTURE_3D, texId);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glLoadIdentity();
		//glTranslate(0.0, -1.0, -2.4);
		glBegin(GL_QUADS);
			for (int i = 0; i < 6; i++)	{
				//first vertex
				glTexCoord3d(vertex[faces[i][0]][0],
					  vertex[faces[i][0]][1],
					  vertex[faces[i][0]][2]);

				glVertex3d(vertex[faces[i][0]][0],
					  vertex[faces[i][0]][1],
					  vertex[faces[i][0]][2]);

				//second vertex
				glTexCoord3d(vertex[faces[i][1]][0],
					  vertex[faces[i][1]][1],
					  vertex[faces[i][1]][2]);

				glVertex3d(vertex[faces[i][1]][0],
					  vertex[faces[i][1]][1],
					  vertex[faces[i][1]][2]);

				//third vertex
				glTexCoord3d(vertex[faces[i][2]][0],
					  vertex[faces[i][2]][1],
					  vertex[faces[i][2]][2]);

				glVertex3d(vertex[faces[i][2]][0],
					  vertex[faces[i][2]][1],
					  vertex[faces[i][2]][2]);

				//fourth vertex
				glTexCoord3d(vertex[faces[i][3]][0],
					  vertex[faces[i][3]][1],
					  vertex[faces[i][3]][2]);

				glVertex3d(vertex[faces[i][3]][0],
					  vertex[faces[i][3]][1],
					  vertex[faces[i][3]][2]);
			}
		glEnd();
			
		glutSwapBuffers();
	}

}

void
processKeys(unsigned char key, int x, int y)
{
        if (key == 27)
             exit(0);
}


void 
changeSize(int w, int h)
{
        if (h==0)                                                                    
                h=1;
        float ratio = w*1.0/h;
        glMatrixMode(GL_PROJECTION);
        
        glLoadIdentity();
        
        glViewport(0,0,w,h);

        gluPerspective(45.0, ratio, 0.1, 100.0);

        glMatrixMode(GL_MODELVIEW);
}

GLuint _texID;

int
main(int argc, char **argv)
{
	stim::texture<unsigned char> stack("/home/pavel/Documents/Test_Data/");
	stim::texture.CreateTexture();
	glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
        glutInitWindowSize(720, 720);
        glutCreateWindow("gl_textures");  
	std::cerr << " Initialization is complete in Glut" << std::endl;
	
        //Process keyboard commands (exit on esc)
        glutKeyboardFunc(&processKeys);
        glutReshapeFunc(&changeSize);
        glutDisplayFunc(&renderScene);
        std::cerr << " Keyboard and Reshape is complete in Glut" << std::endl;

        //Render Scene and such.
        std::cerr << " Loaded Image " << std::endl;
        glutMainLoop();
        return 0;

}