Esempio n. 1
0
void My3DViewer::vertLoader(){
	loader=new myFileDialog(this);

	QString openfile=QFileDialog::getOpenFileName(this, tr("Open File"),"\CIS277",tr("Shader files (*.vert)"));

	if(openfile.compare("")!=0){
		string opens=openfile.toStdString();
		c=new char[opens.length()+1];
			for(int i=0; i<opens.length(); i++){
			c[i]=opens[i];
			cout<<c[i];
		}
		//null terminated string
		c[opens.length()]='\0';
		emit vertFileName(c);
	}
}
Esempio n. 2
0
void setup(int argc, char *argv[])
{
// Put the file paths back to a flatter system because I do not know if
// Windows will barf at the forward slashes and I do not have time to make this
// code check which OS it's using.
//	char temp[256];
//	string vertFileName(getcwd(temp, 255));
//	string fragFileName(getcwd(temp, 255));
//	vertFileName.append("/source/sample2d.vert");
//	fragFileName.append("/source/sample2d.frag");
	string vertFileName("sample3d.vert");
	string fragFileName("sample3d.frag");
	tx = ty = tz = axis = 0.0;

	glutInit( &argc, argv );
	glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH );
	glutInitWindowSize( 800, 600 );

	glutCreateWindow( "Craig McCulloch's Project 4" );

	// Resolves which OpenGL extensions are supported by hardware
	if( glewInit() != GLEW_OK )    {
		cerr << "Error reported by glewInit" << endl;
		exit(1);
	}

	// Orthographic projection
	// Projection
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	gluPerspective( fov, aspect, nearClip, farClip );
	gluLookAt(1.7, 1.5, 2.3, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 );
	// Viewing
	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();
	glTranslatef(-0.5, -0.5, -0.7);

	// Specify 3D RGBA texture
	glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
	glGenTextures( (unsigned int)1, (unsigned int *)&texName );
	glBindTexture( (unsigned int)GL_TEXTURE_3D, (unsigned int)texName );
	glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
	glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
	glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
	glTexImage3D( GL_TEXTURE_3D, 0, GL_RGBA, dr->getX(), dr->getY(), dr->getZ(),
			0, GL_RGBA, GL_UNSIGNED_BYTE, texels );

	// Create shader program
	shaderProgram1 = CreateProgram( vertFileName.c_str(), fragFileName.c_str() );

	// Locate address of shader sampler variable
	TexUnitLocation = glGetUniformLocation( shaderProgram1, "TexUnit" );

	// Assign sampler variable value texture unit 0
	glUniform1i( TexUnitLocation, TexUnit );

	// Callbacks
	glutDisplayFunc( myDraw );
	glutKeyboardFunc( keyboard );
	glutSpecialFunc( specialKeyFunc );

	glutCreateMenu( menu );
	glutAddMenuEntry( "View XY plane (or 'z' key)", 0 );
	glutAddMenuEntry( "View XZ plane (or 'y' key)", 1 );
	glutAddMenuEntry( "View YZ plane (or 'x' key)", 2 );
	glutAddMenuEntry( "Quit (or 'q' key)", 3 );
	glutAttachMenu( GLUT_RIGHT_BUTTON );

	showMenu();
	// Main loop
	glutMainLoop();

}