Exemplo n.º 1
0
int main(int argc, char const *argv[]) {
	printf("Computing Game Of Life On %d x %d Board.\n", DIM_X, DIM_Y);
	
	int *host_current, *host_future, *host_gpu_results;
	int *gpu_current, *gpu_future;
	
	cudaMallocHost((void**) &host_current, DIM_X * DIM_Y * sizeof(int));
	cudaMallocHost((void**) &host_future, DIM_X * DIM_Y * sizeof(int));	
	cudaMallocHost((void**) &host_gpu_results, DIM_X * DIM_Y * sizeof(int));
	cudaMalloc((void**) &gpu_current, DIM_X * DIM_Y * sizeof(int));
	cudaMalloc((void**) &gpu_future, DIM_X * DIM_Y * sizeof(int));
	assert(cudaGetLastError() == cudaSuccess);
	
	fill_board(host_current, 40);
	
	cudaMemcpy(gpu_current, host_current, DIM_X * DIM_Y * sizeof(int), cudaMemcpyHostToDevice);
	setup_textures(gpu_current, gpu_future);
	
	assert(cudaGetLastError() == cudaSuccess);
	
	clock_t start, stop;
	int current_is_a = 1;
	printf("START!\n");
	for(int i = 1; i < 10; i++) {
		start = clock();
		
		int *output = current_is_a ? gpu_future : gpu_current;
		kernel_wrapper(current_is_a, output);
		current_is_a = current_is_a ? 0 : 1;
		
		cudaMemcpy(host_gpu_results, output, DIM_X * DIM_Y * sizeof(int), cudaMemcpyDeviceToHost);
		assert(cudaGetLastError() == cudaSuccess);
		
		stop = clock();
		printf("Time for Textured GPU To Compute Next Phase: %.5f s\n", (float)(stop - start)/CLOCKS_PER_SEC);
				
		start = clock();
		update_board(host_current, host_future);
		stop = clock();
		printf("Time for CPU To Compute Next Phase: %.5f s\n", (float)(stop - start)/CLOCKS_PER_SEC);
		
		printf("======\n");
		check_boards(host_gpu_results, host_future);
				
		int *temp;
		temp = host_current;
		host_current = host_future;
		host_future = temp;
	}
	
	cudaFree(host_future);
	cudaFree(host_current);
	cudaFree(host_gpu_results);
	cudaFree(gpu_current);
	cudaFree(gpu_future);
	
	return 0;
}
Exemplo n.º 2
0
// Our GL Specific Initializations. Returns true On Success, false On Fail.
bool init(void)
{
    glShadeModel(GL_SMOOTH);						   // Enable Smooth Shading
    glClearColor(0.0f, 0.0f, 0.0f, 0.5f);			   // Black Background
    glClearDepth(1.0f);								   // Depth Buffer Setup
    glEnable(GL_DEPTH_TEST);						   // Enables Depth Testing
    glDepthFunc(GL_LEQUAL);							   // The Type Of Depth Testing To Do
	if (!setup_textures()) return false;
	glEnable(GL_TEXTURE_2D);                           // Enable Texture Mapping
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);             // Pixel Storage Mode To Byte Alignment
    glEnable(GL_CULL_FACE);                            // Cull Polygons
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	return true;
}
Exemplo n.º 3
0
Arquivo: renderman.c Projeto: fscz/gre
static int setup_so (SceneData* sceneData, SceneObject* so) {

  SoData* soData = malloc(sizeof(SoData));

  soData->attributes = list_alloc();
  soData->textures = list_alloc();

  GLuint programHandle;

  if ( -1 == setup_program( sceneData, so, soData, &programHandle ) ) return -1;

  if ( -1 == setup_attributes( sceneData, so, soData, programHandle ) ) return -1;  

  if ( -1 == setup_textures ( sceneData, so, soData, programHandle ) ) return -1;

  if ( -1 == setup_index_buffer ( sceneData, so, soData ) ) return -1;

  char soKey[KEYSIZE];
  snprintf ( soKey, KEYSIZE, "%p", so );
  hashmap_insert ( soKey, soData, sceneData->mapSo2SoData );

  return 0;  
}
Exemplo n.º 4
0
int
main(
    int argc,
    char **argv)
{
    const char *input = "input.jpg";

    if (argc < 3) {
        printf("Usage: lfpview basefilename N\n");
        printf("  basefilename_00.jpg, basefilename_01.jpg, ... basefilename_N.jpg and basename_depth.txt will be loaded.\n");
        exit(1);
    }

    input = argv[1];
    gNumLayers = atoi(argv[2]);

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

    init();

    glutCreateWindow("lfp view");

    setup_textures(input);
    load_depth(input);

    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();

    return 0;
}
Exemplo n.º 5
0
//* Function: Main
//* Description: Displays a drawing application using a touchscreen as input
//and draws pixels to the screen according to the user. Uses the DE2 through
//a socket server to do some of the DSP.
//* Input: nothing
//* Returns: 0 or error code
int main(int argc, char const *argv[])
{
	//Init GLFW
	if (!glfwInit())
		exit(EXIT_FAILURE);
	//set error callback
	glfwSetErrorCallback(error_callback);

	//make GLFW window
	GLFWwindow* window = glfwCreateWindow(640, 480, "Webcam DSP", NULL, NULL);
	if (!window)
	{
	    glfwTerminate();
	    exit(EXIT_FAILURE);
	}
	glfwMakeContextCurrent(window);
	//set callback for keys and buttons on window
	glfwSetKeyCallback(window, key_callback);

	float ratio;
	int width, height;

	//Init DE2
	de2_init();

	//bool flag for dsp thread. When 0, the thread
	//will exit, otherwise it will continue running in a loop
	dsp_running = BOOL_TRUE;
	pthread_create(&dsp_thread, NULL, perform_DSP, NULL);

	//generate texture
	glGenTextures(1, &texture[1]);
	glBindTexture(GL_TEXTURE_2D, texture[1]);

	while (!glfwWindowShouldClose(window))
	{
		glfwGetFramebufferSize(window, &width, &height);
		ratio = width / (float) height;

		glViewport(0, 0, width, height);
		glClear(GL_COLOR_BUFFER_BIT);

		glMatrixMode(GL_PROJECTION);
	    glLoadIdentity();
	    glOrtho(-ratio, ratio, -1.f, 1.f, 1.f, -1.f);
	    glMatrixMode(GL_MODELVIEW);
	    glLoadIdentity();

		//make texture
		setup_textures();

		//Draw Processed Data
		glBegin(GL_QUADS);	//draw quads
			glTexCoord2f(TEX_TOP_LEFT); glVertex3f( -ratio, 1.0f, 0.0f);		//top left vertex
			glTexCoord2f(TEX_TOP_RIGHT); glVertex3f( ratio, 1.0f, 0.0);			//top right vertex
			glTexCoord2f(TEX_BOT_RIGHT); glVertex3f( ratio,-1.0f, 0.0);			//bottom right vertex
			glTexCoord2f(TEX_BOT_LEFT); glVertex3f( -ratio, -1.0f, 0.0);		//bottom left vertex
		glEnd();

	    glfwSwapBuffers(window);
	    glfwPollEvents();
	}
	//kill dsp
	dsp_running = BOOL_FALSE;
	pthread_join(dsp_thread, NULL);
	de2_close();
	//kill GLFW
	glfwDestroyWindow(window);
	glfwTerminate();
	printf("done\n");
	return 0;
}
Exemplo n.º 6
0
int
main (int argc, char **argv)
{
    GTimer *timer;
    int frame_count;
    GLuint handle;
    GLenum err;
    GTimer *frame_timer;
    double direction = OPACITY_INCREMENT;

    g_type_init();

    grand = g_rand_new();

    frame_timer = g_timer_new();
    g_timer_start(frame_timer);

    load_data();
    canvas_pixbuf = gdk_pixbuf_new_from_file(CANVAS_FILENAME, NULL);
    g_assert(canvas_pixbuf);

    glutInit(&argc, argv);
    glutCreateWindow("color-convert");
    glutFullScreen();

    err = glewInit();
    g_assert(err == GLEW_OK);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0f, (float) WIDTH, (float) HEIGHT, 0.0f, -1.0f, 1.0f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glDepthRange(0.0f, 1.0f);
    glViewport(0, 0, WIDTH, HEIGHT);
    glRasterPos2f(0.0f, 0.0f);

    glEnable(GL_TEXTURE_2D);

    handle = compile_program();
    glUseProgram(handle);
    setup_textures(handle);

    frame_count = 1;
    timer = g_timer_new();

    while (TRUE) {
        double elapsed;
        GLint location;

        opacity += direction;
        if (opacity >= 1.0) {
            direction = -OPACITY_INCREMENT;
        } else if (opacity <= 0.0) {
            direction = OPACITY_INCREMENT;
        }

        location = glGetUniformLocation(handle, "opacity");
        glUniform1f(location, opacity);

        upload_data();
        draw_scene();

        glutSwapBuffers();

        frame_count ++;

        elapsed = g_timer_elapsed(frame_timer, NULL) * 1000;
        if (elapsed < FRAME_TIME_MS) {
            g_usleep(1000 * (FRAME_TIME_MS - elapsed));
        }

        g_timer_start(frame_timer);

        if (frame_count % 1000 == 0) {
            double fps;

            fps = 1000 / g_timer_elapsed(timer, NULL);
            g_timer_start(timer);
            g_print("Framerate: %gfps\n", fps);
        }
    }
}
Exemplo n.º 7
0
int
main (int argc, char * argv[]) {

    /* initialize glut */
    glutInit (&argc, argv);
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutCreateWindow ("texture");
    glutDisplayFunc (DrawStuff);
    glutMotionFunc (MouseMotion);

    /* create popup menu */
    glutCreateMenu (TextureStyle);
    glutAddMenuEntry ("Texture Off", 301);
    glutAddMenuEntry ("Texture On", 302);
    glutAddMenuEntry ("--------------", 9999);
    glutAddMenuEntry ("Vertex Flat", 501);
    glutAddMenuEntry ("Normal Flat", 502);
    glutAddMenuEntry ("Vertex Cylinder", 503);
    glutAddMenuEntry ("Normal Cylinder", 504);
    glutAddMenuEntry ("Vertex Sphere", 505);
    glutAddMenuEntry ("Normal Sphere", 506);
    glutAddMenuEntry ("--------------", 9999);
    glutAddMenuEntry ("Model Vertex Flat", 507);
    glutAddMenuEntry ("Model Normal Flat", 508);
    glutAddMenuEntry ("Model Vertex Cylinder", 509);
    glutAddMenuEntry ("Model Normal Cylinder", 510);
    glutAddMenuEntry ("Model Vertex Sphere", 511);
    glutAddMenuEntry ("Model Normal Sphere", 512);
    glutAddMenuEntry ("--------------", 9999);
    glutAddMenuEntry ("Check Texture", 701);
    glutAddMenuEntry ("Barberpole Texture", 702);
    glutAddMenuEntry ("Wild Tooth Texture", 703);
    glutAddMenuEntry ("Molten Lava Texture", 704);
    glutAddMenuEntry ("--------------", 9999);
    glutAddMenuEntry ("Exit", 99);
    glutAttachMenu (GLUT_MIDDLE_BUTTON);

    /* initialize GL */
    glClearDepth (1.0);
    glEnable (GL_DEPTH_TEST);
    glClearColor (0.0, 0.0, 0.0, 0.0);
    glShadeModel (GL_SMOOTH);

    glMatrixMode (GL_PROJECTION);
    /* roughly, measured in centimeters */
    glFrustum (-9.0, 9.0, -9.0, 9.0, 50.0, 150.0);
    glMatrixMode(GL_MODELVIEW);

    /* initialize lighting */
    glLightfv (GL_LIGHT0, GL_POSITION, lightOnePosition);
    glLightfv (GL_LIGHT0, GL_DIFFUSE, lightOneColor);
    glEnable (GL_LIGHT0);
    glLightfv (GL_LIGHT1, GL_POSITION, lightTwoPosition);
    glLightfv (GL_LIGHT1, GL_DIFFUSE, lightTwoColor);
    glEnable (GL_LIGHT1);
    glEnable (GL_LIGHTING);
    glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE);
    glEnable (GL_COLOR_MATERIAL);
    glColor3f (0.8, 0.3, 0.6);

    /* initialize and enable texturing */
    setup_textures ();
    gluBuild2DMipmaps (GL_TEXTURE_2D, 3,
                       current_texture -> size,
                       current_texture -> size,
                       GL_RGB, GL_UNSIGNED_BYTE,
                       (void *) (current_texture->pixmap));

    glMatrixMode (GL_TEXTURE);
    glLoadIdentity ();
    glScalef (1.0, 0.1, 1.0);
    glMatrixMode (GL_MODELVIEW);

    glEnable (GL_TEXTURE_2D);
    /*
       some stuff to play with ....
       glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
       glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
       glEnable (GL_TEXTURE_GEN_S);
       glEnable (GL_TEXTURE_GEN_T);
    */

    gleTextureMode (GLE_TEXTURE_ENABLE | GLE_TEXTURE_VERTEX_CYL);

    InitStuff ();

    glutMainLoop ();
    return 0;             /* ANSI C requires main to return int. */
}