コード例 #1
0
ファイル: lista1.cpp プロジェクト: edyp87/uwr_pgk
int main() {
	if(!glfw_init()) return -1;
	opengl_init();
	do {
		display();
	} while(glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS && glfwGetWindowParam( GLFW_OPENED ) );

}
コード例 #2
0
ファイル: display.cpp プロジェクト: GSClaser/labirinth_try_2
bool video_ok::init()
{
  sdl_init();
  opengl_init();
  load_texture();
  if (!id)
    return false;
  return true;
}
コード例 #3
0
int main(int argc, char** argv)
{
  SDL_Event event;

  int keypress = 0;
    
  // Init random number generator
  srand(clock());

  // Init everything
  sdl_init("OpenGL example");
  opengl_init();
  audioplayer_init();
  
  // Init internal data
  init_sin_table();
  init_textures();
  
  // Load audioplayer tune
  audioplayer_loadtune(&simpletune);
  audioplayer_play();
  
  // Loop until the end
  while(!keypress && audioplayer_isplaying()) 
  {
    // Lock SDL surface if needed
    if(SDL_MUSTLOCK(screen)) 
      if(SDL_LockSurface(screen) < 0)
	exit(EXIT_FAILURE);
  
    // Draw the plasma
    draw_cube(screen, audioplayer_getpos());

    // Unlock the SDL surface if needed
    if(SDL_MUSTLOCK(screen))
      SDL_UnlockSurface(screen);
  
    // Update screen
    SDL_GL_SwapBuffers();
      
    // Handle SDL events
    while(SDL_PollEvent(&event)) 
    {      
      switch (event.type) 
      {
	case SDL_QUIT:
	case SDL_KEYDOWN:
	  keypress = 1;
	  break;
      }
    }
  }
  
  // Exit gracefully
  SDL_Quit();
  return EXIT_SUCCESS;
}
コード例 #4
0
ファイル: main.cpp プロジェクト: gsygsygsyd/OpenGL
int main(void)
{

//	register_func(fbo_init, fbo_draw);
	register_func(vao_init, vao_draw);
	GLFWwindow* window;
	if (!glfwInit())
		return -1;

	window = glfwCreateWindow(800, 800, "Simple example", NULL, NULL);
	if (!window)
	{
		glfwTerminate();
		return -1;
	}

	glfwMakeContextCurrent(window);

	GLenum glew_err = glewInit();
	if (glew_err != GLEW_OK)
	{
		printf("%s\n", glewGetErrorString(glew_err));
		return -1;
	}

	opengl_init();

	while (!glfwWindowShouldClose(window))
	{
		opengl_draw(1);
		glfwSwapBuffers(window);
		glfwPollEvents();
	}

	glfwDestroyWindow(window);

	glfwTerminate();
	return 1;
}
コード例 #5
0
/****** Initialize LCD with SDL ******/
bool AGB_LCD::init()
{
	//Initialize with SDL rendering software or hardware
	if(config::sdl_render)
	{
		//Initialize all of SDL
		if(SDL_Init(SDL_INIT_VIDEO) == -1)
		{
			std::cout<<"LCD::Error - Could not initialize SDL video\n";
			return false;
		}

		//Setup OpenGL rendering
		if(config::use_opengl) {opengl_init(); }

		//Set up software rendering
		else
		{
			window = SDL_CreateWindow("GBE+", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, config::sys_width, config::sys_height, config::flags);
			SDL_GetWindowSize(window, &config::win_width, &config::win_height);
			final_screen = SDL_GetWindowSurface(window);
			original_screen = SDL_CreateRGBSurface(SDL_SWSURFACE, config::sys_width, config::sys_height, 32, 0, 0, 0, 0);
			config::scaling_factor = 1;
		}

		if(final_screen == NULL) { return false; }
	}

	//Initialize with only a buffer for OpenGL (for external rendering)
	else if((!config::sdl_render) && (config::use_opengl))
	{
		final_screen = SDL_CreateRGBSurface(SDL_SWSURFACE, config::sys_width, config::sys_height, 32, 0, 0, 0, 0);
	}

	std::cout<<"LCD::Initialized\n";

	return true;
}
コード例 #6
0
ファイル: main.c プロジェクト: elekmad/SDL_basic_GL
int main( int argc, char *argv[ ] )
{
    SDL_Window *window;
    if( SDL_Init( SDL_INIT_VIDEO ) == -1 )
    {
        printf( "Can't init SDL:  %s\n", SDL_GetError( ) );
        return EXIT_FAILURE;
    }

    if( SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1) == -1)
    {
        printf( "Can't set attribute DOUBLE BUFFER :  %s\n", SDL_GetError( ) );
        return EXIT_FAILURE;
    }
    atexit( SDL_Quit );
    SDL_Surface *surface;
    window = SDL_CreateWindow("Ma fenêtre de jeu", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL );

    SDL_GLContext *glcontext;
    glcontext = SDL_GL_CreateContext(window);

    int nValue;
    if( SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &nValue) < 0)
    {
        printf("Echec de recuperation du parametre SDL_GL_DOUBLEBUFFER : %s\n", SDL_GetError());
        return (EXIT_FAILURE);
    }

    // assurons nous que le mode "double buffer" est bien actif
    if(nValue != 1)
    {
        printf("Erreur : SDL_GL_DOUBLEBUFFER inactif : %d\n", nValue);
        return (EXIT_FAILURE);
    }
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
    SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &nValue);
    printf("Depth %d\n", nValue);

    surface = SDL_GetWindowSurface(window);

    if( surface == NULL )
    {
        printf( "Can't set video mode: %s\n", SDL_GetError( ) );
        return EXIT_FAILURE;
    }   

    opengl_init();
    // Main loop
    SDL_Event event;
    while(1)
    {
        opengl_clear(window);

       // Check for messages
        if (SDL_PollEvent(&event))
        {
            // Check for the quit message
            switch (event.type)
            {
                case SDL_QUIT:
                    SDL_Quit();
                    return EXIT_SUCCESS;// Quit the program
                    break;
				case SDL_KEYUP:
				case SDL_KEYDOWN:
					//printf("keydown %d\n", event.key.keysym.sym);
					switch(event.key.keysym.sym)
					{
					case SDLK_DOWN:
						t_y += (event.type == SDL_KEYDOWN ? SPEED_RATE : 0);
                                                printf("y = %f\n", t_y);
						break;
					case SDLK_UP:
						t_y -= (event.type == SDL_KEYDOWN ? SPEED_RATE : 0);
                                                printf("y = %f\n", t_y);
						break;
					case SDLK_LEFT:
						t_x += (event.type == SDL_KEYDOWN ? SPEED_RATE : 0);
                                                printf("y = %f\n", t_x);
						break;
					case SDLK_RIGHT:
						t_x -= (event.type == SDL_KEYDOWN ? SPEED_RATE : 0);
                                                printf("x = %f\n", t_x);
						break;
					case SDLK_PAGEUP:
						t_z += (event.type == SDL_KEYDOWN ? SPEED_RATE : 0);
                                                printf("z = %f\n", t_z);
						break;
					case SDLK_PAGEDOWN:
						t_z -= (event.type == SDL_KEYDOWN ? SPEED_RATE : 0);
                                                printf("z = %f\n", t_z);
						break;


					case SDLK_ESCAPE:
						SDL_Quit();
						return EXIT_SUCCESS;// Quit the program
						break;
					}
					//printf("speed %f\n", rotationspeed);
					break;
            }
        }
       
        uint32_t new_tick = SDL_GetTicks();
        if(new_tick - delay > 100)
        {
            delay = new_tick;
            rotation += rotationspeed;
            if(rotation > 360)
                rotation -= 360;
            if(rotation < 0)
                rotation += 360;
            //printf("rotation of %f\n", rotation);
        }

        glRotatef(rotation, 1.0f, 1.5f, 0.0f);

        draw_cube();
        //Swap the GL bufers, front and back.
        SDL_GL_SwapWindow(window);
        
    }

    // Tell the SDL to clean up and shut down
    SDL_Quit();

    return EXIT_SUCCESS;
}
コード例 #7
0
ファイル: init.cpp プロジェクト: shonumi/gel
/****** Initializes SDL, OpenGL and Video and Window ******/
bool init()
{
    
	/* Initialize All SDL Systems */
	if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
	{
		std::cout<<"SDL could not be initialized!\n";
		return false;    
	}

	/* Use OpenGL for Rendering */
	if(gfx::hw_accel)
	{
		/* Initialize SDL Video - OpenGL */
		if(SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_RESIZABLE | SDL_OPENGL) == NULL) 
		{
			std::cout<<"SDL Video could not be initialized!\n";
			return false;
		}

		/* Initialize OpenGL */
		if(opengl_init() == false) 
		{
			std::cout<<"OpenGL could not be initialized!\n";
			return false;
		}

		std::cout<<"Renderer - OpenGL \n";
	}

	/* Use SDL for Rendering */
	else 
	{
		/* Initialize SDL Video - SDL */
		gfx::main_screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);

		if(gfx::main_screen == NULL)
		{
			std::cout<<"SDL Video could not be initialized!\n";
			return false;
		}

		std::cout<<"Renderer - SDL \n";
	}
		
 
	/* Initialize TTF */
	if(TTF_Init() == -1) 
	{
		std::cout<<"SDL TTF could not be initialized\n";
		return false; 
	}

	/* Load controller configuration */
	if(!load_controller_config("Config/controls.xgl")) { return false; }

	SDL_WM_SetCaption("RPG Game - Development", NULL);

	/* Print other info */
	std::cout<<"RPG Game copyright Daniel & Alex Baxter 2012\n";
	std::cout<<"Version 0.1 " << __DATE__ << " " << __TIME__ << "\n";

	return true;
}
コード例 #8
0
/**********************************************************************
 * Initialize OpenGL ES and EGL
***********************************************************************/
static int engine_init_display(struct engine* engine)
{
    /*
     * Here specify the attributes of the desired configuration.
     * Below, we select an EGLConfig with at least 8 bits per color
     * component compatible with on-screen windows
     */
    const EGLint attribs[] = {
        EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
        EGL_BLUE_SIZE, 8,
        EGL_GREEN_SIZE, 8,
        EGL_RED_SIZE, 8,
        EGL_ALPHA_SIZE, 8,
        EGL_DEPTH_SIZE, 16,
        EGL_NONE
    };
    EGLint w, h, dummy, format;
    EGLint numConfigs;
    EGLConfig config;
    EGLSurface surface;
    EGLContext context;

    EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);

    eglInitialize(display, 0, 0);

    /* Here, the application chooses the configuration it desires. In this
     * sample, we have a very simplified selection process, where we pick
     * the first EGLConfig that matches our criteria */
    eglChooseConfig(display, attribs, &config, 1, &numConfigs);

    /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
     * guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
     * As soon as we picked a EGLConfig, we can safely reconfigure the
     * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
    eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);

    ANativeWindow_setBuffersGeometry(engine->app->window, 0, 0, format);

    surface = eglCreateWindowSurface(display, config, engine->app->window, NULL);

    EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
    context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribs);


    if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE)
    {
        LOGW("Unable to eglMakeCurrent");
        return -1;
    }

    eglQuerySurface(display, surface, EGL_WIDTH, &w);
    eglQuerySurface(display, surface, EGL_HEIGHT, &h);

    engine->display = display;
    engine->context = context;
    engine->surface = surface;
    engine->width = w;
    engine->height = h;

    if(engine->app != NULL && engine->app->activity != NULL)
    {
        mgr = engine->app->activity->assetManager;
    }
    opengl_init(w,h);
    LOGI("opengl init");

    return 0;
}
コード例 #9
0
int main(int argc, char *argv[])
{	 
	// Set the translation part to be the identity.
	locked_matrix[3][0] = locked_matrix[3][1] = locked_matrix[3][2] = 0;
	locked_matrix[0][3] = locked_matrix[1][3] = locked_matrix[2][3] = 0;
	locked_matrix[3][3] = 1;

	locked_matrix[0][0] = locked_matrix[1][1] = locked_matrix[2][2] = 1;
	locked_matrix[0][1] = locked_matrix[1][0] = locked_matrix[2][0] = locked_matrix[0][2]= locked_matrix[2][1] = locked_matrix[1][2]=0;
	
	memcpy(&final_matrix,locked_matrix[0],sizeof last_matrix);

	try
	{
		
		bcm_host_init();
		opengl_init();
		projection_init();
		textures_init();
		model_board_init();
		printf("AHRS Textures loaded\n");
		fflush(stdout);
		
		uint32_t time_start = 0;
		int missed = 0;
		uint32_t time_fps = 0;
		int fps = 0;
		uint32_t time_delay = 0;
			
		//non blocking sdtin read
		fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL, 0) | O_NONBLOCK);
	
		while(1)
		{			
	
			time_start += 20;
			uint32_t predicted_delay = time_start - millis(); //calc predicted delay
			if (predicted_delay > 20) predicted_delay = 0; //check for overflow
			if (predicted_delay != 0){
				delay(predicted_delay); 
				time_delay += predicted_delay;
			}else{
				time_start = millis(); //reset timer to now
				printf("AHRS Skipping Idle...\n");
				missed++;
			}

			int count = 1;
			char buffer[100];
			//stdin is line buffered so we can cheat a little bit
			while (count > 0){ // dump entire buffer
				count = read(STDIN_FILENO, buffer, sizeof(buffer));
				if (count > 1){ //ignore blank lines
					buffer[count-1] = '\0'; //replace last char with string ending
					//printf("!%s!\n",buffer);
					//check the line
					int temp[4];
					
					int result = sscanf(buffer,"%d %d %d", &temp[0], &temp[1],  &temp[2]);
					if (result != 3){
						fprintf(stderr, "AHRS Unrecognized input with %d items.\n", result);
					}else{
						acceleration[0] = temp[1];
						acceleration[1] = temp[2];
						acceleration[2] = 0;
						frame = temp[0];
					}
					
				}
			}
			if (state != frame){
				printf("AHRS Entering Mode %d\n",frame);
				state = frame;
				changes++;
			}	
			redraw_scene();

			fps++;
			if (time_fps < millis()){
				printf("AHRS FPS:%d  mis:%d idle:%d%% changes:%d\n",fps,missed,time_delay/10, changes);
				fps = 0;
				time_delay = 0;
				time_fps += 1000;
				if (time_fps < millis()) time_fps = millis()+1000;	
			}		
			
		}
		
		opengl_deinit();
		bcm_host_deinit();
		return 0;
	}
	catch(const std::exception & error)
	{
		std::cerr << "Error: " << error.what() << std::endl;
		exit(9);
	}
}