Exemplo n.º 1
0
bool RendererOpenGL::Initialize(void)
{
	if(InitializeSDL() == false)
	{
		return false;
	}

	glClearColor(0, 0, 0, 0);
	glClearDepth(1.0f);
 
	glViewport(0, 0, RenderManager::GetInstance()->GetWindowWidth(), RenderManager::GetInstance()->GetWindowHeight());
 
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	gluPerspective(
		45.0f,
		(GLfloat)RenderManager::GetInstance()->GetWindowWidth()/(GLfloat)RenderManager::GetInstance()->GetWindowHeight(),
		0.1f,
		100.0f);
 
	glMatrixMode(GL_MODELVIEW);
 
	glEnable(GL_TEXTURE_2D);
 
	glLoadIdentity();

	glEnable(GL_DEPTH_TEST);							// Enables Depth Testing
	glDepthFunc(GL_LEQUAL);								// The Type Of Depth Testing To Do
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations

	return true;
}
Exemplo n.º 2
0
Window::Window(unsigned int widthInit, unsigned int heightInit, std::string title)
	: width{widthInit}, height{heightInit}
{
	InitializeSDL();
	InitializeIMG();
	InitializeMixer();
	SetUpWindow(width, height, title);
}
Exemplo n.º 3
0
MediaLayer::MediaLayer(std::unique_ptr<Application> inputApp, std::unique_ptr<Renderer> inputRenderer):
    app(std::move(inputApp)), renderer(std::move(inputRenderer)), sdlWindow(nullptr), sdlInitialized(false), openglInitialized(false)
{
    assert(app);
    assert(renderer);

    InitializeSDL();
    InitializeOpenGL();

    renderer->Initialize();
    app->Initialize();
}
Exemplo n.º 4
0
bool GameWindow::Initialize() {
	InitializeSDL();
	InitializeGL();
	InitializeShaderContext(); // In Shader.cpp

    audioManager->Initialize();
	gameModeManager->Initialize();

	//audioManager->Play("music/grinch.wav", AUDIO_LOCAL);

	return true;
}
Exemplo n.º 5
0
// Initialization functions
void GameApp::InitApp(void)
{
    #ifndef GL_ARB_texture_non_power_of_two
        printf("DOES NOT SUPPORT NON POWER OF TWO!!\n");
    #else
        printf("DOES SUPPORT NON POWER OF TWO!!\n");
    #endif
    printf("InitApp...\n");
    ResW = 600;
    ResH = 600;
//    ilInit();
    InitializeSDL();
    InitializeDrawContext(ResW, ResH);
    ResetGame();
    InstallTimer();

    //player1 = new GameSprite;
//    PlayerX.SetWorldX(0);
//    PlayerX.SetWorldY(0);
//    PlayerX.SetOrientation(0.0);
    //context.DrawTexture(context.GetBackground(),0 , 0);
}
Exemplo n.º 6
0
void InitializeAudio(int freq)
{    
    if(SDL_WasInit(SDL_INIT_AUDIO|SDL_INIT_TIMER) == (SDL_INIT_AUDIO|SDL_INIT_TIMER) ) 
    {
#ifdef DEBUG
        printf("[JttL's SDL Audio plugin] Debug: Audio and timer allready initialized.\n");
#endif
    }
    else 
    {
#ifdef DEBUG
        printf("[JttL's SDL Audio plugin] Debug: Audio and timer not yet initialized. Initializing...\n");
#endif
        InitializeSDL();
    }
    if (critical_failure == 1)
        return;
    GameFreq = freq; // This is important for the sync
    if(hardware_spec != NULL) free(hardware_spec);
    SDL_PauseAudio(1);
    SDL_CloseAudio();

    // Prototype of our callback function
    void my_audio_callback(void *userdata, Uint8 *stream, int len);

    // Open the audio device
    SDL_AudioSpec *desired, *obtained;
    
    // Allocate a desired SDL_AudioSpec
    desired = malloc(sizeof(SDL_AudioSpec));
    
    // Allocate space for the obtained SDL_AudioSpec
    obtained = malloc(sizeof(SDL_AudioSpec));
    
    // 22050Hz - FM Radio quality
    //desired->freq=freq;
    
    if(freq < 11025) OutputFreq = 11025;
    else if(freq < 22050) OutputFreq = 22050;
    else OutputFreq = 44100;
    
    desired->freq = OutputFreq;
    
#ifdef DEBUG
    printf("[JttL's SDL Audio plugin] Debug: Requesting frequency: %iHz.\n", desired->freq);
#endif
    /* 16-bit signed audio */
    desired->format=AUDIO_S16SYS;
#ifdef DEBUG
    printf("[JttL's SDL Audio plugin] Debug: Requesting format: %i.\n", desired->format);
#endif
    /* Stereo */
    desired->channels=2;
    /* Large audio buffer reduces risk of dropouts but increases response time */
    desired->samples=SecondaryBufferSize;

    /* Our callback function */
    desired->callback=my_audio_callback;
    desired->userdata=NULL;

    if(buffer == NULL)
    {
        printf("[JttL's SDL Audio plugin] Allocating memory for audio buffer: %i bytes.\n", (int) (PrimaryBufferSize*sizeof(Uint8)));
        buffer = (Uint8*) malloc(PrimaryBufferSize);
    }

    if (mixBuffer == NULL)
    {
        //this should be the size of the SDL audio buffer
        mixBuffer = (Uint8*) malloc(SecondaryBufferSize * 4);
    }

    memset(buffer, 0, PrimaryBufferSize * sizeof(Uint8));

    /* Open the audio device */
    if ( SDL_OpenAudio(desired, obtained) < 0 )
    {
        fprintf(stderr, "[JttL's SDL Audio plugin] Error: Couldn't open audio: %s\n", SDL_GetError());
        critical_failure = 1;
        return;
    }
    /* desired spec is no longer needed */

    if(desired->format != obtained->format)
    {
        fprintf(stderr, "[JttL's SDL Audio plugin] Error: Obtained audio format differs from requested.\n");
    }
    if(desired->freq != obtained->freq)
    {
        fprintf(stderr, "[JttL's SDL Audio plugin] Error: Obtained frequency differs from requested.\n");
    }
    free(desired);
    hardware_spec=obtained;

#ifdef DEBUG
    printf("[JttL's SDL Audio plugin] Debug: Frequency: %i\n", hardware_spec->freq);
    printf("[JttL's SDL Audio plugin] Debug: Format: %i\n", hardware_spec->format);
    printf("[JttL's SDL Audio plugin] Debug: Channels: %i\n", hardware_spec->channels);
    printf("[JttL's SDL Audio plugin] Debug: Silence: %i\n", hardware_spec->silence);
    printf("[JttL's SDL Audio plugin] Debug: Samples: %i\n", hardware_spec->samples);
    printf("[JttL's SDL Audio plugin] Debug: Size: %i\n", hardware_spec->size);
#endif
    SDL_PauseAudio(0);
    
    /* set playback volume */
    if (VolumeControlType == VOLUME_TYPE_SDL)
    {
        VolSDL = SDL_MIX_MAXVOLUME * VolPercent / 100;
    }
    else
    {
        VolPercent = volGet();
    }

}
Exemplo n.º 7
0
bool App::InitApp (void)
{
#ifdef CONFDIR
    strcpy (settings_path, (std::string (CONFDIR) + PATH_SEPARATOR + "test3d.ini").c_str());
#else
    strcpy (settings_path, (std::string (SDL_GetBasePath ()) + "settings.ini").c_str());
#endif

    int w, h;

    // initialize SDL with screen sizes from settings file:
    w = LoadSetting (settings_path, SCREENWIDTH_SETTING);
    if (w < 640)
        w = 640;

    h = LoadSetting (settings_path, SCREENHEIGHT_SETTING);
    if (h < 480)
        h = 480;

    fullscreen = LoadSetting (settings_path, FULLSCREEN_SETTING) > 0 ? true : false;

    // Create a window:
    if (!InitializeSDL(w, h))
        return false;

    // Create a rendering context in the window:
    if (!InitializeGL())
        return false;

    pScene = new HubScene (this);

    RandomSeed ();

    Progress progress;
    Loader loader;

    // Collect jobs to be done:
    pScene->AddAll (&loader);

    // Progress bar is rendered in a different thread while the scene loads:
    bool error = false;
    SDL_Thread* progressThread = MakeSDLThread (
                                    [&] () { return ProgressLoop (mainWindow, &progress, error); },
                                    "progress"
                                 );
    if (!progressThread)
    {
        SetError ("failed to create progress thread: %s", SDL_GetError());
        return false;
    }

    /*
        Do all jobs while the progress bar is rendered.
        Some of them depend on the current thread's rendering context.
     */
    if (!loader.LoadAll (&progress))
    {
        error = true;
        SDL_DetachThread (progressThread);
        return false;
    }

    // progressThread will finish automatically, now that everything is loaded ..

    // Check for other errors:
    if (!CheckGLOK ("scene init"))
        return false;

    // Wait for progress display thread to finish:
    int progressReturn;
    SDL_WaitThread (progressThread, &progressReturn);
    if (progressReturn != 0)
    {
        SetError ("progress thread returned exit code %d", progressReturn);
        return false;
    }

    return true;
}