Пример #1
0
void VideoEngine::DrawLine(float x1, float y1, float x2, float y2, float width, const Color& color)
{
    GLfloat vert_coords[] = {
        x1, y1,
        x2, y2
    };
    EnableBlending();
    DisableTexture2D();
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal blending
    glPushAttrib(GL_LINE_WIDTH);

    glLineWidth(width);
    EnableVertexArray();
    DisableColorArray();
    DisableTextureCoordArray();
    glColor4fv((GLfloat *)color.GetColors());
    glVertexPointer(2, GL_FLOAT, 0, vert_coords);
    glDrawArrays(GL_LINES, 0, 2);

    glPopAttrib(); // GL_LINE_WIDTH
}
Пример #2
0
bool VideoEngine::ApplySettings()
{
    if(_target == VIDEO_TARGET_SDL_WINDOW) {
        // Losing GL context, so unload images first
        if(TextureManager && TextureManager->UnloadTextures() == false) {
            IF_PRINT_WARNING(VIDEO_DEBUG) << "failed to delete OpenGL textures during a context change" << std::endl;
        }

        int32 flags = SDL_OPENGL;

        if(_temp_fullscreen == true) {
            flags |= SDL_FULLSCREEN;
        }

        SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
        SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 2);
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
        SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);

        if(SDL_SetVideoMode(_temp_width, _temp_height, 0, flags) == false) {
            // RGB values of 1 for each and 8 for depth seemed to be sufficient.
            // 565 and 16 here because it works with them on this computer.
            // NOTE from prophile: this ought to be changed to 5558
            SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
            SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
            SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
            SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
            SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
            SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
            SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
            SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);

            if(SDL_SetVideoMode(_temp_width, _temp_height, 0, flags) == false) {
                IF_PRINT_WARNING(VIDEO_DEBUG) << "SDL_SetVideoMode() failed with error: " << SDL_GetError() << std::endl;

                _temp_fullscreen = _fullscreen;
                _temp_width = _screen_width;
                _temp_height = _screen_height;

                if(TextureManager && _screen_width > 0) {  // Test to see if we already had a valid video mode
                    TextureManager->ReloadTextures();
                }
                return false;
            }
        }

        // Clear GL state, after SDL_SetVideoMode() for OSX compatibility
        DisableBlending();
        DisableTexture2D();
        DisableAlphaTest();
        DisableStencilTest();
        DisableScissoring();
        DisableVertexArray();
        DisableColorArray();
        DisableTextureCoordArray();

        // Turn off writing to the depth buffer
        glDepthMask(GL_FALSE);

        _screen_width = _temp_width;
        _screen_height = _temp_height;
        _fullscreen = _temp_fullscreen;

        if(TextureManager)
            TextureManager->ReloadTextures();

        return true;
    } // if (_target == VIDEO_TARGET_SDL_WINDOW)

    // Used by the editor, which uses QT4
    else if(_target == VIDEO_TARGET_QT_WIDGET) {
        _screen_width = _temp_width;
        _screen_height = _temp_height;
        _fullscreen = _temp_fullscreen;

        return true;
    }

    return false;
} // bool VideoEngine::ApplySettings()