Пример #1
0
int main(int argc, char *argv[])
{
        glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA|GLUT_ALPHA|GLUT_DOUBLE|GLUT_DEPTH);//added alpha.
        glutInitWindowSize(800,600);
        glutCreateWindow("My First Triangle");

	GLenum glew_status = glewInit();
	if (glew_status != GLEW_OK)
	{
		fprintf(stderr, "Error: %s\n", glewGetErrorString(glew_status));
		return 1;
	}

	if (init_resources())
	{
	        glutDisplayFunc(display);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	        glutMainLoop();
		//and that is all the changes for this iteration. give it a go. the next bits of commentary
		//will be in the shader source files. so head on over to those files and take a look!
	}

	free_resources();
        return 0;
}
Пример #2
0
int main(int argc, char *argv[])
{
        glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA|GLUT_ALPHA|GLUT_DOUBLE|GLUT_DEPTH);
        glutInitWindowSize(800,600);
        glutCreateWindow("My First Triangle");
	glutIdleFunc(idle);

	GLenum glew_status = glewInit();
	if (glew_status != GLEW_OK)
	{
		fprintf(stderr, "Error: %s\n", glewGetErrorString(glew_status));
		return 1;
	}

	if (init_resources())
	{
	        glutDisplayFunc(display);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	        glutMainLoop();
	}

	free_resources();
        return 0;
}
Пример #3
0
int main (int argc, char* argv[])
{
  glutInit (&argc, argv);
  glutInitDisplayMode (GLUT_RGBA|GLUT_ALPHA|GLUT_DOUBLE|GLUT_DEPTH);
  glutInitWindowSize (WINDOW_WIDTH, WINDOW_HEIGHT);
  glutCreateWindow ("triangle2");

  /* Init glew */
  GLenum glew_status = glewInit();
  if (glew_status != GLEW_OK)
    {
      fprintf (stderr, "Error: %s\n", glewGetErrorString (glew_status));
      exit (EXIT_FAILURE);
    }

  /* Check version of OpenGL */
  if (!GLEW_VERSION_2_0) {
    fprintf (stderr, "Error: your graphics card does not support OpenGL 2.0\n");
    exit (EXIT_FAILURE);
  }

  if (1 == init_resources() )
    {
      glutDisplayFunc (onDisplay);
      glutKeyboardFunc(keyboard_char);      
      glEnable (GL_BLEND);
      glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      glutMainLoop ();
    }

  free_resources ();
  exit (EXIT_SUCCESS);
}
Пример #4
0
int main(int argc, char* argv[]) {
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA|GLUT_ALPHA|GLUT_DOUBLE|GLUT_DEPTH);
	glutInitWindowSize(x_resolution, y_resolution);
	glutCreateWindow("Mandelbrot");

	GLenum glew_status = glewInit();
	if (glew_status != GLEW_OK) {
		fprintf(stderr, "Error: %s\n", glewGetErrorString(glew_status));
		return 1;
	}

	if (!GLEW_VERSION_2_0) {
		fprintf(stderr, "Error: your graphic card does not support OpenGL 2.0\n");
		return 1;
	}

	if (init_resources()) {
		glutDisplayFunc(onDisplay);
		glutReshapeFunc(onReshape);
		glutKeyboardFunc(keyboardCallback);
		glutSpecialFunc(SpecialInput);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glutMainLoop();
	}

	free_resources();
	return 0;
}
Пример #5
0
int main(int argc, char* argv[]) {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA|GLUT_ALPHA|GLUT_DOUBLE|GLUT_DEPTH);
    glutInitWindowSize(screen_width, screen_height);
    glutCreateWindow("My Rotating Cube");

    GLenum glew_status = glewInit();
    if (glew_status != GLEW_OK) {
        fprintf(stderr, "Error: %s\n", glewGetErrorString(glew_status));
        return 1;
    }

    if (!GLEW_VERSION_2_0) {
        fprintf(stderr, "Error: your graphic card does not support OpenGL 2.0\n");
        return 1;
    }

    if (init_resources()) {
        glutDisplayFunc(onDisplay);
        glutReshapeFunc(onReshape);
        glutMouseFunc(onMouse);
        glutMotionFunc(onMouseDrag);
        glutIdleFunc(onIdle);
        glEnable(GL_BLEND);
        glEnable(GL_DEPTH_TEST);
        //glDepthFunc(GL_LESS);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glutMainLoop();
    }

    free_resources();
    return 0;
}
Пример #6
0
int coap_cmd(int argc, char **argv) {
    coap_context_t  *ctx;
    struct timeval tv, *timeout;
    coap_tick_t now;
    coap_queue_t *nextpdu;
    coap_log_t log_level = LOG_WARNING;

    coap_set_log_level(log_level);

    ctx = get_context();
    if (!ctx)
        return -1;

    init_resources(ctx);

    while ( !quit ) {
        nextpdu = coap_peek_next( ctx );

        coap_ticks(&now);
        while (nextpdu && nextpdu->t <= now - ctx->sendqueue_basetime) {
            coap_retransmit( ctx, coap_pop_next( ctx ) );
            nextpdu = coap_peek_next( ctx );
        }

        if ( nextpdu && nextpdu->t <= COAP_RESOURCE_CHECK_TIME ) {
            /* set timeout if there is a pdu to send before our automatic timeout occurs */
            tv.tv_usec = ((nextpdu->t) % COAP_TICKS_PER_SECOND) * 1000000 / COAP_TICKS_PER_SECOND;
            tv.tv_sec = (nextpdu->t) / COAP_TICKS_PER_SECOND;
            timeout = &tv;
        } else {
            tv.tv_usec = 0;
            tv.tv_sec = COAP_RESOURCE_CHECK_TIME;
            timeout = &tv;
        }

        (void) timeout;

        coap_read(ctx);	/* read received data */
        coap_dispatch(ctx);	/* and dispatch PDUs from receivequeue */

#ifndef WITHOUT_ASYNC
        /* check if we have to send asynchronous responses */
        check_async(ctx, now);
#endif /* WITHOUT_ASYNC */

#ifndef WITHOUT_OBSERVE
        /* check if we have to send observe notifications */
        coap_check_notify(ctx);
#endif /* WITHOUT_OBSERVE */
    }

    coap_free_context( ctx );

    return 0;
}
Пример #7
0
void test_change_item(CuTest * tc)
{
    unit * u;

    test_cleanup();
    init_resources();
    test_create_world();

    u = test_create_unit(0, 0);
    test_uchange(tc, u, get_resourcetype(R_IRON));
}
Пример #8
0
int main(int argc, char *argv[]) {
	SDL_Init(SDL_INIT_VIDEO);
	SDL_Window *window = SDL_CreateWindow("My Graph",
			SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
			640, 480,
			SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
	SDL_GLContext context = SDL_GL_CreateContext(window);
	SDL_GL_SetSwapInterval(1);

	GLenum glew_status = glewInit();

	if (GLEW_OK != glew_status) {
		fprintf(stderr, "Error: %s\n", glewGetErrorString(glew_status));
		return 1;
	}

	if (!GLEW_VERSION_2_0) {
		fprintf(stderr, "No support for OpenGL 2.0 found\n");
		return 1;
	}

	GLint max_units;

	glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &max_units);
	if (max_units < 1) {
		fprintf(stderr, "Your GPU does not have any vertex texture image units\n");
		return 1;
	}

	printf("Use left/right/up/down to move.\n");
	printf("Use pageup/pagedown to change the horizontal scale.\n");
	printf("Press home to reset the position and scale.\n");
	printf("Press F1 to toggle interpolation.\n");
	printf("Press F2 to toggle clamping.\n");
	printf("Press F3 to toggle rotation.\n");
	printf("Press F4 to toggle polygon offset.\n");

	if (!init_resources())
		return EXIT_FAILURE;

	mainLoop(window);

	free_resources();

	SDL_GL_DeleteContext(context);
	SDL_DestroyWindow(window);
	SDL_Quit();

	return EXIT_SUCCESS;
}
Пример #9
0
int main(int argc, char* argv[]) {
	/* Glut-related initialising functions */
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA|GLUT_ALPHA|GLUT_DOUBLE|GLUT_DEPTH);
	glutInitWindowSize(screen_width, screen_height);
	glutCreateWindow(title.c_str());

	/* Extension wrangler initialising */
	GLenum glew_status = glewInit();
	if (glew_status != GLEW_OK) {
		fprintf(stderr, "Error: %s\n", glewGetErrorString(glew_status));
		return EXIT_FAILURE;
	}
	if (!GLEW_VERSION_2_0) {
		fprintf(stderr, "Error: your graphic card does not support OpenGL 2.0\n");
		return 1;
	}

	/* When all init functions runs without errors,
	the program can initialise the resources */
	if (init_resources() == 1) {
		/* And then we can display it if everything goes OK */
		if(isFullscreen)
			glutFullScreen();
		//glEnable(GL_CULL_FACE);
		glutSetCursor(GLUT_CURSOR_NONE);
		glEnable(GL_BLEND);
		glEnable(GL_DEPTH_TEST);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glutIdleFunc(idle);
		glutReshapeFunc(onReshape);
		glutDisplayFunc(onDisplay);

		glutPassiveMotionFunc(onMouseMove);
		glutMotionFunc(onMouseMove);

		glutKeyboardFunc(onKeyDown);
		glutKeyboardUpFunc(onKeyUp);
		glutSpecialFunc(onKeyDownSpecial);
		glutSpecialUpFunc(onKeyUpSpecial);
		
		glutTimerFunc(250, threadFunc, 4);
		glutMainLoop();
	}

	/* If the program exits in the usual way,
	free resources and exit with a success */
	free_resources();
	return EXIT_SUCCESS;
}
Пример #10
0
int main(/*int argc, char *argv[]*/){
	screen = {1920,1080};
	SDL_Init(SDL_INIT_VIDEO);

	// Select an OpenGL 2.1 profile.
	//SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);

	SDL_Window *window = SDL_CreateWindow("Voxel Engine",
		SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
		screen.x, screen.y,
		SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);

	SDL_GLContext context = SDL_GL_CreateContext(window);

	GLenum err;
	glewExperimental = GL_TRUE;
	if((err=glewInit()) != GLEW_OK){
		std::cout << "GLEW was not able to initialize! Error: " << glewGetErrorString(err) << std::endl;
		return -1;
	}

	// Set relative mouse mode, this will grab the cursor.
	SDL_SetRelativeMouseMode(SDL_TRUE);

	SDL_GL_SetSwapInterval(0);
	ui::reshape(window, screen.x, screen.y);

	print_opengl_info();

	if (!init_resources())
		return EXIT_FAILURE;

	glEnable(GL_BLEND);
	glEnable(GL_DEPTH_TEST);
	//glDepthFunc(GL_LESS);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	mainLoop(window);

	free_resources();

    SDL_GL_DeleteContext(context);
    SDL_DestroyWindow(window);
	SDL_Quit();

    return 0; // Calls everything passed to atexit
}
Пример #11
0
static void test_resourcename_no_appearance(CuTest *tc) {
    const resource_type *rtype;

    test_cleanup();
    init_resources(); // creates R_SILVER
    rtype = get_resourcetype(R_SILVER);
    assert(rtype && rtype->itype);
    assert(rtype->itype->_appearance[0] == 0);
    assert(rtype->itype->_appearance[1] == 0);
    CuAssertStrEquals(tc, "money", resourcename(rtype, 0));
    CuAssertStrEquals(tc, "money_p", resourcename(rtype, NMF_PLURAL));
    CuAssertStrEquals(tc, "money", resourcename(rtype, NMF_APPEARANCE));
    CuAssertStrEquals(tc, "money_p", resourcename(rtype, NMF_APPEARANCE | NMF_PLURAL));
    test_cleanup();
}
Пример #12
0
int main(int argc, char* argv[]) {
	/* Glut-related initialising functions */
	glutInit(&argc, argv);
//glutInitContextVersion(4, 0);
//glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
	glutInitContextProfile(GLUT_CORE_PROFILE);

	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION); //alternative GLUT_ACTION_GLUTMAINLOOP_RETURNS

	glutInitDisplayMode(GLUT_RGBA | GLUT_ALPHA | GLUT_DOUBLE | GLUT_DEPTH);

	glutInitWindowSize(640, 480);
	glutCreateWindow("Tetris");

	/* Extension wrangler initialising */
	GLenum glew_status = glewInit();
	if (glew_status != GLEW_OK) {
		fprintf(stderr, "Error: %s\n", glewGetErrorString(glew_status));
		return EXIT_FAILURE;
	}

	/* When all init functions run without errors,
	 the program can initialise the resources */
	if (1 == init_resources()) {
		/* We can display it if everything goes OK */

		glutDisplayFunc(onDisplay);
		glutReshapeFunc(onReshape);

		glutKeyboardFunc(onKeyPressed);
		glutSpecialFunc(specialKeyPressed);
		glutMouseFunc(onMouse);
		glutMotionFunc(onMotion);
		glutMouseWheelFunc(onMouseWheel);

		glEnable(GL_BLEND);
		glEnable(GL_DEPTH_TEST);
		glutTimerFunc(0, timerCallBack, 0);
		//glDepthFunc(GL_LESS);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glutMainLoop();
	}

	/* If the program exits in the usual way,
	 free resources and exit with a success */
	free_resources();
	return EXIT_SUCCESS;
}
Пример #13
0
int start_openGL(int argc, char *argv[]) {
	glutInit(&argc, argv);// glut initialise something so that rendering will be enababled
	glutInitDisplayMode(GLUT_RGBA|GLUT_ALPHA|GLUT_DOUBLE|GLUT_DEPTH);// tell glut how to render output: rgba colorsm alpha channel, double buffers for smooth rendering, stores the depth in the render of polygons etc..
	glutInitWindowSize(Environment::screen_width, Environment::screen_height); // sets the default window size
	glutCreateWindow("Maze Game Johannes and Marcus");               // create a window with a title

	// Extension wrangler initialising 
	GLenum glew_status = glewInit();    // init the extension
	if (glew_status != GLEW_OK) {       // if not success
		std::cerr << "Error: "<< glewGetErrorString(glew_status) << std::endl;    // error msg
		return EXIT_FAILURE;
	}
	if (!GLEW_VERSION_2_0) {            // if not right version
		std::cerr << "Error: your graphic card does not support OpenGL 2.0\n";  // error msg
		return 1;
	}

	// When all init functions runs without errors,
	// the program can initialise the resources 
	if (init_resources() == 1) {    // if we were able to init the resources
        // Go ahead and setup the opengl-Environment::game properties
		if(Environment::isFullscreen)    // if fullscreen will show att start
			glutFullScreen();// set fullscreen on the window 
		//glEnable(GL_CULL_FACE);   // draw both sides of one face
		// glutSetCursor(GLUT_CURSOR_NONE);// make the cursor vanish
		glEnable(GL_BLEND);         // make opengl blend-mode enabled
		glEnable(GL_DEPTH_TEST);    // make opengl depth-test enabled
		glDisable(GL_CULL_FACE);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		glutReshapeFunc(onReshape); // if the window resizes onReshape will be called
		glutIdleFunc(idle);         // idle will be called every frame
		glutDisplayFunc(onDisplay); // onDisplay function will draw/update the screen vissually

		glutPassiveMotionFunc(onMouseMove);// onMouseMove is called when the mouse is moving
		glutMotionFunc(onMouseMove);       // onMouseMove is called when the mouse is moving and mouse button is down

		glutKeyboardFunc(onKeyDown);        // onKeyDown will be called when a key has ben pressed
		glutKeyboardUpFunc(onKeyUp);        // onKeyUp will be called when a key has ben released
		glutSpecialFunc(onKeyDownSpecial);  // special keys like F1,F2...F9 and arrows etc 
		glutSpecialUpFunc(onKeyUpSpecial);
		
		glutMainLoop();                     // starts the main program/the window that was created
	}
	return 0;
}
Пример #14
0
// Compile a given string containing GLSL into SPV for use by VK
// Return value of false means an error was encountered.
bool GLSLtoSPV(const VkShaderStageFlagBits shader_type,
	const char *pshader,
	std::vector<unsigned int> &spirv, std::string *errorMessage) {

	glslang::TProgram program;
	const char *shaderStrings[1];
	TBuiltInResource Resources;
	init_resources(Resources);

	// Enable SPIR-V and Vulkan rules when parsing GLSL
	EShMessages messages = (EShMessages)(EShMsgSpvRules | EShMsgVulkanRules);

	EShLanguage stage = FindLanguage(shader_type);
	glslang::TShader shader(stage);

	shaderStrings[0] = pshader;
	shader.setStrings(shaderStrings, 1);

	if (!shader.parse(&Resources, 100, false, messages)) {
		puts(shader.getInfoLog());
		puts(shader.getInfoDebugLog());
		if (errorMessage) {
			*errorMessage = shader.getInfoLog();
			(*errorMessage) += shader.getInfoDebugLog();
		}
		return false; // something didn't work
	}

	// Note that program does not take ownership of &shader, so this is fine.
	program.addShader(&shader);

	if (!program.link(messages)) {
		puts(shader.getInfoLog());
		puts(shader.getInfoDebugLog());
		if (errorMessage) {
			*errorMessage = shader.getInfoLog();
			(*errorMessage) += shader.getInfoDebugLog();
		}
		return false;
	}

	// Can't fail, parsing worked, "linking" worked.
	glslang::GlslangToSpv(*program.getIntermediate(stage), spirv);
	return true;
}
Пример #15
0
int main(int argc, char* argv[]) {
  step = gsl_matrix_complex_alloc(N,N);
  psi = gsl_matrix_complex_alloc(N,N);
  temp = gsl_matrix_complex_alloc(N,N);
  initial_max =init_wave_function( psi , circular_step_pdf );
  normalization = 1;
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
  glutInitWindowSize(width, height);
  glutCreateWindow("graph");

  GLenum glew_status = glewInit();
  if (GLEW_OK != glew_status) {
    fprintf(stderr, "Error: %s\n", glewGetErrorString(glew_status));
    return 1;
  }

  if (!GLEW_VERSION_2_0) {
    fprintf(stderr, "No support for OpenGL 2.0 found\n");
    return 1;
  }

  GLint max_units;
  glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &max_units);
  if(max_units < 1) {
	  fprintf(stderr, "Your GPU does not have any vertex texture image units\n");
	  return 1;
  }

  if (init_resources()) {
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutSpecialFunc(special);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutKeyboardFunc(keyboard);
    glutMainLoop();
  }

  free_resources();
  return 0;
} 
Пример #16
0
static void test_core_resources(CuTest *tc) {
    resource_type * rtype;
    test_cleanup();
    init_resources();
    CuAssertPtrNotNull(tc, rtype = rt_find("money"));
    CuAssertPtrNotNull(tc, rtype->itype);
    CuAssertPtrNotNull(tc, rtype->uchange);
    CuAssertPtrNotNull(tc, rtype->itype->give);
    CuAssertPtrNotNull(tc, rtype = rt_find("peasant"));
    CuAssertPtrEquals(tc, 0, rtype->itype);
    CuAssertPtrNotNull(tc, rtype = rt_find("person"));
    CuAssertPtrEquals(tc, 0, rtype->itype);
    CuAssertPtrNotNull(tc, rtype = rt_find("permaura"));
    CuAssertPtrEquals(tc, 0, rtype->itype);
    CuAssertPtrNotNull(tc, rtype = rt_find("hp"));
    CuAssertPtrEquals(tc, 0, rtype->itype);
    CuAssertPtrNotNull(tc, rtype = rt_find("aura"));
    CuAssertPtrEquals(tc, 0, rtype->itype);
    test_cleanup();
}
Пример #17
0
int open_session(int eflag)
{
	SaErrorT rv;

        if (!g_thread_supported()) {
                g_thread_init(NULL);
	};
	thread_wait = g_cond_new();
	thread_mutex = g_mutex_new();
	do_progress("Discover");
	rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &sessionid, NULL);
	if (rv != SA_OK) {
     		printf("saHpiSessionOpen error %s\n", oh_lookup_error(rv));
		return -1;
	}
	if (eflag) {
		show_event_short = 1;
		prt_flag = 1;
		pthread_create(&ge_thread, NULL, get_event, NULL);
	};
	rv = saHpiDiscover(sessionid);
	if (rv != SA_OK) {
		delete_progress();
		printf("saHpiDiscover rv = %s\n", oh_lookup_error(rv));
		return -1;
	};
	delete_progress();

	printf("Initial discovery done\n");

	Domain = init_resources(sessionid);
	if (Domain == (Domain_t *)NULL) {
     		printf("init_resources error\n");
		return -1;
	}
	printf("\tEnter a command or \"help\" for list of commands\n");

	if (! eflag)
		pthread_create(&ge_thread, NULL, get_event, NULL);
	return 0;
}
Пример #18
0
void init_ui(bool fullscreen) {
    int width = 640, height = 480;
    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2);
    screen = SDL_CreateWindow("putkijuoksu",
                          SDL_WINDOWPOS_UNDEFINED,
                          SDL_WINDOWPOS_UNDEFINED,
                          width, height,
                          (fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0) |
                          SDL_WINDOW_OPENGL);
 
    if(screen == NULL)
        throw "could not init SDL / opengl";
    SDL_GetWindowSize(screen, &width, &height);
    SDL_GL_CreateContext(screen);
    SDL_SetRelativeMouseMode(SDL_TRUE);
    SDL_SetCursor(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW));

    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(40, (double)width/(double)height, 0.1, 100);
    glMatrixMode(GL_MODELVIEW);
    glClearColor(0, 1, 1, 1);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glEnable(GL_MULTISAMPLE);

    glClearColor(0.5f,0.5f,0.5f,1.0f);
    glFogi(GL_FOG_MODE, GL_LINEAR);
    GLfloat fog_color[] = {0.5, 0.5, 0.5, 1};
    glFogfv(GL_FOG_COLOR, fog_color);
    glFogf(GL_FOG_DENSITY, 0.35f);
    glHint(GL_FOG_HINT, GL_DONT_CARE);
    glFogf(GL_FOG_START, VIEWDISTANCE-5);
    glFogf(GL_FOG_END, VIEWDISTANCE+5);
    glEnable(GL_FOG);
    init_resources();
}
Пример #19
0
int main(int argc, char *argv[]) {
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGB);
	glutInitWindowSize(640, 480);
	glutCreateWindow("Basic Text");
	glutTimerFunc(30, TimerFunction, 1);
	glewInit();
	glEnable(GL_TEXTURE_2D);                        // Enable Texture Mapping ( NEW )
    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
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);         



	if (init_resources()) {
			/////////////////////////
	glGenTextures(1, &texture[0]);                  // Create The Texture
 
	// Typical Texture Generation Using Data From The Bitmap
	glBindTexture(GL_TEXTURE_2D, texture[0]);
	FT_Set_Pixel_Sizes(face, 0, 48);

	FT_Load_Char( face, 'o', FT_LOAD_RENDER );
	FT_GlyphSlot g = face->glyph;

	
	gluBuild2DMipmaps(GL_TEXTURE_2D,  GL_RED, g->bitmap.width, g->bitmap.rows,  GL_RED, GL_UNSIGNED_BYTE, g->bitmap.buffer);

    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
	////////////////////////
		glutDisplayFunc(display);
		glutMainLoop();
	}

	getchar();
	return 0;
}
Пример #20
0
int		main(int argc, char **argv)
{
  t_princ	lemip;
  int		ret;

  if ((ret = init_resources(&lemip)) == EXIT_FAILURE)
    {
      fprintf(stderr, "Can't create resources requiered for the battle !\n");
      return (EXIT_FAILURE);
    }
  if (init_player(&lemip, argv[1], (argc > 1) ? argv[2] : NULL) == EXIT_FAILURE)
    return (EXIT_FAILURE);
  if (ret == 2)
    {
      exec_map(&lemip);
      destroy_resources(&lemip);
    }
  else
    (lemip.ia_take == 1) ? ia_intermediate(&lemip) : ia_easy(&lemip);
  return (EXIT_SUCCESS);
}
Пример #21
0
int main(int argc, char* argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA|GLUT_ALPHA|GLUT_DOUBLE|GLUT_DEPTH);
    glutInitWindowSize(init_screen_width, init_screen_height);
    glutCreateWindow(DEFAULT_CAPTION);

    GLenum glew_status = glewInit();
    if(glew_status != GLEW_OK) {
        fprintf(stderr, "Error: %s\n", glewGetErrorString(glew_status));
        return 1;
    }

    if(!GLEW_VERSION_2_0) {
        fprintf(stderr, "Error: your graphic card does not support OpenGL 2.0\n");
        return 1;
    }

    char* s = (char*)glGetString(GL_SHADING_LANGUAGE_VERSION);
    printf("GLSL version %s\n", s);

    if(init_resources()) {
        glutDisplayFunc(onDisplay);
        glutKeyboardFunc(onKeyboard);
        glutSpecialFunc(onSpecial);
        glutSpecialUpFunc(onSpecialUp);
        glutMouseFunc(onMouse);
        glutMotionFunc(onMotion);
        glutReshapeFunc(onReshape);
        glutIdleFunc(onIdle);
        //glEnable(GL_BLEND);
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_CULL_FACE);
        //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glutMainLoop();
    }

    return 0;
}
Пример #22
0
bool GLSLtoSPV(const VkShaderStageFlagBits shaderType, const char *shaderText,
			   std::vector<unsigned int> &spirv) {

	EShLanguage stage = FindLanguage(shaderType);
	glslang::TShader shader(stage);
	glslang::TProgram program;
	const char *shaderStrings [1];
	TBuiltInResource Resources;
	init_resources(Resources);

	// Enable SPIR-V and Vulkan rules when parsing GLSL
	EShMessages messages = (EShMessages) (EShMsgSpvRules | EShMsgVulkanRules);

	shaderStrings [0] = shaderText;
	shader.setStrings(shaderStrings, 1);

	if(!shader.parse(&Resources, 100, false, messages)) {
		puts(shader.getInfoLog());
		puts(shader.getInfoDebugLog());
		return false; // something didn't work
	}

	program.addShader(&shader);

	//
	// Program-level processing...
	//

	if(!program.link(messages)) {
		puts(shader.getInfoLog());
		puts(shader.getInfoDebugLog());
		fflush(stdout);
		return false;
	}

	glslang::GlslangToSpv(*program.getIntermediate(stage), spirv);
	return true;
}
Пример #23
0
/** creates a small world and some stuff in it.
 * two terrains: 'plain' and 'ocean'
 * one race: 'human'
 * one ship_type: 'boat'
 * one building_type: 'castle'
 * in 0.0 and 1.0 is an island of two plains, around it is ocean.
 */
void test_create_world(void)
{
  terrain_type *t_plain, *t_ocean;
  region *island[2];
  int i;
  const char * names[] = { "horse", "horse_p", "boat", "boat_p", "iron", "iron_p", "stone", "stone_p" };

  make_locale("de");
  init_resources();
  assert(!olditemtype[I_HORSE]);

  olditemtype[I_HORSE] = test_create_itemtype(names+0);
  olditemtype[I_IRON] = test_create_itemtype(names+4);
  olditemtype[I_STONE] = test_create_itemtype(names+6);

  t_plain = test_create_terrain("plain", LAND_REGION | FOREST_REGION | WALK_INTO | CAVALRY_REGION);
  t_plain->size = 1000;
  t_ocean = test_create_terrain("ocean", SEA_REGION | SAIL_INTO | SWIM_INTO);
  t_ocean->size = 0;

  island[0] = test_create_region(0, 0, t_plain);
  island[1] = test_create_region(1, 0, t_plain);
  for (i = 0; i != 2; ++i) {
    int j;
    region *r = island[i];
    for (j = 0; j != MAXDIRECTIONS; ++j) {
      region *rn = r_connect(r, (direction_t)j);
      if (!rn) {
        rn = test_create_region(r->x + delta_x[j], r->y + delta_y[j], t_ocean);
      }
    }
  }

  test_create_race("human");

  test_create_buildingtype("castle");
  test_create_shiptype(names+2);
}
Пример #24
0
JNIEXPORT void JNICALL Java_com_ssb_droidsound_plugins_VICEPlugin_N_1setDataDir(JNIEnv *env, jclass cl, jstring path)
{
    const char* cpath = env->GetStringUTFChars(path, 0);

    __android_log_print(ANDROID_LOG_VERBOSE, "VICEPlugin", "setRootDir() to %s", cpath);
    maincpu_early_init();
    machine_setup_context();
    drive_setup_context();
    machine_early_init();
    sysfile_init("C64");

    gfxoutput_early_init(0);

    if (init_resources() < 0)
    {
        archdep_startup_log_error("Failed to init resources");
        return;
    }

    /* Set factory defaults.  */
    if (resources_set_defaults() < 0)
    {
        archdep_startup_log_error("Cannot set defaults.\n");
        return;
    }

    resources_set_int("SidResidSampling", 0);
    resources_set_int("VICIIVideoCache", 0);
    resources_set_string("Directory", cpath);

    if (init_main() < 0)
    {
        archdep_startup_log_error("Failed to init main");
        return;
    }

    env->ReleaseStringUTFChars(path, cpath);
}
Пример #25
0
int main(int argc, char* argv[])
{
  srand(1337);
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGBA|GLUT_ALPHA|GLUT_DEPTH|GLUT_DOUBLE);
  glutInitWindowSize(screen_width, screen_height);
  glutCreateWindow("Network Visualizer");
  GLenum glew_status = glewInit();
  if (glew_status != GLEW_OK)
  {
    fprintf(stderr, "Error: %s\n", glewGetErrorString(glew_status));
    return 1;
  }
  if (!GLEW_VERSION_2_0)
  {
    fprintf(stderr, "Error: Graphics Card does not seem to support OpenGL 2.0\n");
    return 1;
  }
  if (init_resources())
  {
    glutDisplayFunc(onDisplay);
    glutReshapeFunc(onReshape);
    glutIgnoreKeyRepeat(1);
    glutMouseFunc(onMouse);
    glutKeyboardFunc(pressKey);
    glutKeyboardUpFunc(releaseKey);
    glutIdleFunc(onIdle);
    glEnable(GL_BLEND);
    glEnable(GL_ALPHA_TEST);
    glDisable(GL_DEPTH_TEST);
    glEnable(GL_DEPTH_TEST);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glutMainLoop();
  }
  return 0;
}
Пример #26
0
void MyGLWindow::initializeGL()
{
  init_resources();

  // load texture if specified
  if (_textureName != "")
  {
    _texture0 = SOIL_load_OGL_texture
      (
      _textureName.c_str(),
      SOIL_LOAD_AUTO,
      SOIL_CREATE_NEW_ID,
      SOIL_FLAG_MIPMAPS 
      );
  
    /* check for an error during the load process */
    if( 0 == _texture0 )
    {
      printf( "SOIL loading error: '%s' '%s'\n", SOIL_last_result(), _textureName.c_str() );
    }
    else
    {
      glEnable(GL_TEXTURE_2D);
    }    
  }

  // Enable alpha blend
 //   glEnable(GL_BLEND);
 //   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  // set the clear colour
  glClearColor(1,1,1,1);

  // Start timer
  gettimeofday(&_startTime, NULL);
}
Пример #27
0
int main() {
	msgbuf_t * msgbuf;
	int msgqid;
	int clientqid;
	unsigned int numTypes;
	key_t key;
	int messageNum;
	
	unsigned int * available;
	unsigned int * maxAvailable;
	sorted_array_t clients;
	client_info_t  * client;
	
	char decreasingFlag;
	
	//variables for the do while loop
	int i;
	int flag;
	
	init_resources(&numTypes, &available);
	
	maxAvailable = (unsigned int *) malloc(numTypes * sizeof(unsigned int));
	if(maxAvailable == NULL) {
		perror("malloc maxAvailable");
		cleanup(0, available, maxAvailable, clients, msgbuf, msgqid);
		exit(1);
	}
	memcpy(maxAvailable, available, numTypes * sizeof(unsigned int));
	
	clients.size = 4;
	clients.items = 0;
	clients.clientInfo = (client_info_t *) malloc(clients.size * sizeof(client_info_t));
	if(clients.clientInfo == NULL) {
		perror("malloc clients.clientInfo");
		cleanup(1, available, maxAvailable, clients, msgbuf, msgqid);
		exit(1);
	}
	
	msgbuf = (msgbuf_t *) malloc(MSGBUF_SIZE);
	if(msgbuf == NULL) {
		perror("malloc msgbuf");
		cleanup(2, available, maxAvailable, clients, msgbuf, msgqid);
		exit(1);
	}
	
	//Make exclusive mailbox
	key = BANK_MSGQUE_KEY;
	msgqid = msgget(key, 0420 | IPC_EXCL | IPC_CREAT);
	if(msgqid == NULL) {
		// Failed to create queue
		perror("msgget");
		cleanup(3, available, maxAvailable, clients, msgbuf, msgqid);
		exit(1);
	}
	
	decreasingFlag = 0;
	messageNum = 1;
	do {
		//Wait for requests of any kind
		if( msgrcv(msgqid, msgbuf, REQUEST_SIZE, 0, 0) == -1) {
			//if there was an error:
			perror("msgrcv");
			cleanup(4, available, maxAvailable, clients, msgbuf, msgqid);
			exit(1);
		};
		clientqid = msgbuf->request.sender;
		
		//display request
		printf("Received message at queueID %u:\n", msgqid);
		display_msg(msgbuf, numTypes);
		
		//process requests
		switch(msgbuf->mtype) {
			case 1:
				//client requesting resources
				client = get_client(&clients, msgbuf->request.sender);
				for(i=0, flag=0; i<numTypes || flag; i++) {
					//calculate client needs
					client->needs[i] = client->claims[i] - client->allocated[i];
					//Does client request fit they're max claims?
					flag = msgbuf->request.resourceVector[i] > client->needs[i];
				}
				
				//No
				if(flag) {
					msgbuf->mtype = 6;
					printf("\tFAILED REQUEST\n");
				}
				else {
					//Yes
					for(i=0, flag=0; i<numTypes || flag; i++) {
						//do we have the resources available?
						flag = msgbuf->request.resourceVector[i] > available[i];
					}
					//No
					if(flag) {
						msgbuf->mtype = 12;
						printf("\tFAILED REQUEST\n");
					}
					else {
						//Yes
						client = get_client(&clients, msgbuf->request.sender);
						for(i=0; i<numTypes; i++) {
							client->allocated[i] += msgbuf->request.resourceVector[i];
							client->needs[i] -= msgbuf->request.resourceVector[i];
							available -= msgbuf->request.resourceVector[i];
						}
						if(bankers_algorithm(clients, available, numTypes)) {
							//success
							msgbuf->mtype = 4;
							printf("\tGRANTED REQUEST\n");
						}
						else {
							//failure
							client->allocated[i] -= msgbuf->request.resourceVector[i];
							client->needs[i] += msgbuf->request.resourceVector[i];
							available += msgbuf->request.resourceVector[i];
							
							msgbuf->mtype = 5;
							printf("\tFAILED REQUEST\n");
						}
					}
				}
				break;
			case 2:
				//client releasing resources
				client = get_client(&clients, msgbuf->request.sender);
				for(i=0, flag=0; i<numTypes || flag; i++) {
					//are they releasing resources that they actually have?
					flag = msgbuf->request.resourceVector[i] > client->allocated[i];
				}
				if(!flag) {
					//yes
					for(i=0; i<numTypes; i++) {
						available[i] += msgbuf->request.resourceVector[i];
						client->allocated -= msgbuf->request.resourceVector[i];
					}
					msgbuf->mtype = 7;
					
					
					printf("\tGRANTED RELEASE\n");
				}
				else {
					//No
					msgbuf->mtype = 8;
					
					printf("\tDENIED RELEASE\n");
				}
				break;
			case 3:
				//client registering max resources
				for(i=0, flag=0; i<numTypes || flag; i++) {
					//does the claim fit my max resources?
					flag = msgbuf->request.resourceVector[i] > maxAvailable[i];
				}
				if(!flag) {
					//this claim will fit my max resources
					//I shall register you
					client = (client_info_t *) malloc(sizeof(client_info_t));
					if(client == NULL) {
						perror("malloc client info");
						flag = 1;
					}
					else {
						client->claims = (unsigned int *) malloc(sizeof(unsigned int) * numTypes);
						client->allocated = (unsigned int *) calloc(numTypes, sizeof(unsigned int));
						client->needs = (unsigned int *) malloc(sizeof(unsigned int) * numTypes);
						
						if(client->claims == NULL 
							|| client->allocated == NULL
							|| client->needs == NULL) {
							//failed to allocate arrays
							perror("malloc client resource arrays");
							free(client->claims);
							free(client->allocated);
							free(client->needs);
							free(client);
							flag = 1;
						}
						else {
							add_client(&clients, client);
							memcpy(client->claims, msgbuf->request.resourceVector,
								numTypes * sizeof(unsigned int));
							
							//send success message
							msgbuf->mtype = 9;
						}
					}
				}
				
				if(flag) {
					//this claim will not fit my max resources
					msgbuf->mtype = 10;
				}
				break;
			case 11:
				//client releasing all resources
				client = get_client(&clients, msgbuf->request.sender);
				for(i=0; i<numTypes; i++) {
					available[i] += client->allocated[i];
				}
				remove_client(&clients, msgbuf->request.sender);
				decreasingFlag = 1;
				break;
			default:
				//bad or unprocessed type, so ignore it
				break;
		}
		
		msgbuf->request.sender = 0;
		msgbuf->request.inReply = messageNum;
		msgbuf->request.retAddr = msgqid;
		//display reply
		printf("Sent message to queueID %u:\n", clientqid);
		display_msg(msgbuf, numTypes);
		
		//Send reply
		msgsend(clientqid, msgbuf, REQUEST_SIZE, 0);
		messageNum++;
		
		//Display status
		
	} while(decreasingFlag && clients.items > 0);
	
	cleanup(-1, available, maxAvailable, clients, msgbuf, msgqid);
	return 0;
}
Пример #28
0
	void clear() {
		free_resources();
		init_resources();
	}
Пример #29
0
	Pool() : pos_m(0) {
		init_resources();
	}
Пример #30
0
int main(int argc, char * argv[])
{
	int i;
	for (i = 1; i < argc; i++) {
		if (strcmp(argv[i], "-help") == 0
		    || strcmp(argv[i], "-h") == 0)
		{
			show_help(argc, argv);
			return 0;
		}
		else if (strcmp(argv[i], "-res") == 0) {
			show_resources();
			return 0;
		}
	}

	init_appres(argc, argv);
	the_bar.realized = 0;

	if (!get_display_info() ||
	    !init_resources() ||
	    !create_main_window())
		exit (1);

	set_signals();
	XMapWindow(gdi.display, gdi.mainw);

	set_keybindings();

	XEvent evt;
	while (1) {
		XNextEvent(gdi.display, &evt);
#ifdef DEBUG
		printf("wid %08X\t%s\n", (int)(evt.xany.window),
		       event_names[evt.type]);
		fflush(stdout);
#endif

		switch(evt.type){
		case KeyPress:
			handle_key_press(&evt);
			break;
		case ReparentNotify:
			handle_reparent(&evt);
			break;
		case MapRequest:
			/* add a new tab */
			handle_maprequest(&evt);
			break;
		case DestroyNotify:
			/* remove a tab */
			handle_destroy(&evt);
			break;
		case ConfigureNotify:
			handle_configure_notify(&evt);
			break;
		case ConfigureRequest:
			handle_configure_request(&evt);
			break;
		case Expose:
			if (evt.xexpose.window != gdi.mainw)
				bar_handle_expose(&(evt.xexpose));
			break;
		case ButtonPress:
			bar_handle_button(&(evt.xbutton));
			break;
		case PropertyNotify:
			bar_handle_prop(&evt);
			break;
		case MapNotify:
			if (evt.xmap.window == gdi.mainw) {
				if (init_stage == 0) {
					init_stage ++;
					spawn_xterm();
				}
			}
			break;
		case UnmapNotify:
			if (the_bar.tab_group.tab_count == 0)
				exit(0);
			break;
		case EnterNotify:
			set_focus();
			break;
		default:
			break;
		}
		XFlush(gdi.display);
	};
	return 0;
}