Пример #1
0
void OpenGL::setShadingMode( ShadingMode shadingMode )
{
    LOCK

    currentShadingMode_ = shadingMode;

    switch( shadingMode ){
        case ShadingMode::SOLID_LIGHTING_AND_TEXTURING:
            setProgram( ShaderProgramType::DEFAULT );
            enableLighting();
            enableTexturing();
        break;
        case ShadingMode::SOLID_LIGHTING:
            setProgram( ShaderProgramType::DEFAULT );
            enableLighting();
            disableTexturing();
        break;
        case ShadingMode::SOLID_PLAIN:
            setProgram( ShaderProgramType::DEFAULT );
            disableLighting();
            disableTexturing();
        break;
        case ShadingMode::NORMALS:
            setProgram( ShaderProgramType::NORMALS );
        break;
    }
}
Пример #2
0
bool GraphicsDeviceGL_1_3::init(int w, int h, int& vw, int& vh)
{
	m_platform->init();
	queryExtensions();

	//we need to support at least 512x512 textures in order to get 320x200 or 320x240
	if (m_caps.maxTextureSize2D < 512)
	{
		LOG( LOG_ERROR, "The OpenGL 1.3 graphics device does not support at least 512x512 textures which is required by the XL Engine." );
		return false;
	}

	//clamp the virtual screen by the maximum texture size.
	while (vw > (s32)m_caps.maxTextureSize2D || vh > (s32)m_caps.maxTextureSize2D)
	{
		vw >>= 1;
		vh >>= 1;
	}

    glDisable(GL_DEPTH_TEST); /* enable depth buffering */

	glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

	glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    /* establish initial viewport */
	// fix the height to the actual screen height.
	// calculate the width such that wxh has a 4:3 aspect ratio (assume square pixels for modern LCD monitors).
	// offset the viewport by half the difference between the actual width and 4x3 width
	// to automatically pillar box the display.
	// Unfortunately, for modern monitors, only 1200p yields exact integer scaling. So we do all the scaling on
	// the horizontal axis, where there are more pixels, to limit the visible distortion.
	int w4x3 = (h<<2) / 3;
	int dw   = w - w4x3;
	m_virtualViewportNoUI[0] = dw>>1;
	m_virtualViewportNoUI[1] = 0;
	m_virtualViewportNoUI[2] = w4x3;
	m_virtualViewportNoUI[3] = h;

	for (int i=0; i<4; i++) { m_virtualViewport[i] = m_virtualViewportNoUI[i]; }

	m_fullViewport[0] = 0;
	m_fullViewport[1] = 0;
	m_fullViewport[2] = w;
	m_fullViewport[3] = h;

	m_windowWidth  = w;
	m_windowHeight = h;

	//frame size - this is the 32 bit version of the framebuffer. The 8 bit framebuffer, rendered by the software renderer,
	//is converted to 32 bit (using the current palette) - this buffer - before being uploaded to the video card.
	m_frameWidth  = vw;
	m_frameHeight = vh;
	m_frameBuffer_32bpp[0] = new u32[ m_frameWidth*m_frameHeight ];
	m_frameBuffer_32bpp[1] = new u32[ m_frameWidth*m_frameHeight ];

	//Create a copy of the framebuffer on the GPU so we can upload the results there.
	const SamplerState samplerState=
	{
		WM_CLAMP, WM_CLAMP, WM_CLAMP,							//clamp on every axis
		TEXFILTER_LINEAR, TEXFILTER_POINT, TEXFILTER_POINT,		//filtering
		false													//no mipmapping
	};
	m_videoFrameBuffer = createTextureRGBA_Internal(m_frameWidth, m_frameHeight, NULL, samplerState);
	enableTexturing(true);

	glFlush();

	return true;
}