Exemplo n.º 1
0
//=============================================================================
//Setup GL
//@returns TRUE on success, FALSE otherwise
//=============================================================================
boolean GLApp::SetupGL()
{
	//smooth shading & depth test
	glShadeModel(GL_SMOOTH);
	glEnable(GL_DEPTH_TEST);
	
	//enable lighting operations
	GLfixed diffuse[] = { FTOX(1.0f), FTOX(1.0f), FTOX(1.0f), FTOX(1.0f) };
	GLfixed lightPos[] = { FTOX(0.0f), FTOX(5.0f), FTOX(-5.0f) };
	glEnable(GL_LIGHT0);
	glEnable(GL_COLOR_MATERIAL);
	glLightxv(GL_LIGHT0, GL_DIFFUSE, diffuse);
	glLightxv(GL_LIGHT0, GL_POSITION, lightPos);
	
	//enable blending operations
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

	//enable fog operations
	GLfixed fogColor[] = { 0, 0, 0, ITOX(1) };
	glFogxv(GL_FOG_COLOR, fogColor);
	glFogx(GL_FOG_MODE, GL_LINEAR);
	glFogx(GL_FOG_START, ITOX(10));
	glFogx(GL_FOG_END, ITOX(70));	

	//perspective Correction
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	
	//GL Initialization
	glViewport(0, 0, m_DBitmapInfo.cx, m_DBitmapInfo.cy);
	
	//init Projection matrix
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glFrustumx(ITOX(-5), ITOX(5), ITOX(-5), ITOX(5), ITOX(10), ITOX(100));
	
	//init Model-View matrix
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	if(glGetError() != GL_NO_ERROR) 
		return FALSE;
	
	return TRUE;
}
Exemplo n.º 2
0
static void configureLightAndMaterial()
{
    static GLfixed light0Position[] = { -0x40000, 0x10000, 0x10000, 0 };
    static GLfixed light0Diffuse[] = { 0x10000, 0x6666, 0, 0x10000 };
    static GLfixed light1Position[] = { 0x10000, -0x20000, -0x10000, 0 };
    static GLfixed light1Diffuse[] = { 0x11eb, 0x23d7, 0x5999, 0x10000 };
    static GLfixed light2Position[] = { -0x10000, 0, -0x40000, 0 };
    static GLfixed light2Diffuse[] = { 0x11eb, 0x2b85, 0x23d7, 0x10000 };
    static GLfixed materialSpecular[] = { 0x10000, 0x10000, 0x10000, 0x10000 };

    glLightxv(GL_LIGHT0, GL_POSITION, light0Position);
    glLightxv(GL_LIGHT0, GL_DIFFUSE, light0Diffuse);
    glLightxv(GL_LIGHT1, GL_POSITION, light1Position);
    glLightxv(GL_LIGHT1, GL_DIFFUSE, light1Diffuse);
    glLightxv(GL_LIGHT2, GL_POSITION, light2Position);
    glLightxv(GL_LIGHT2, GL_DIFFUSE, light2Diffuse);
    glMaterialxv(GL_FRONT_AND_BACK, GL_SPECULAR, materialSpecular);

    glMaterialx(GL_FRONT_AND_BACK, GL_SHININESS, 60 << 16);
    glEnable(GL_COLOR_MATERIAL);
}
void glLightxvLogged(GLenum light, GLenum pname, const GLfixed *params) {
	printf("glLightxv(%s, %s, %p)\n", GLEnumName(light), GLEnumName(pname), params);
	PrintGLData(1, GL_FIXED, 0, 4, params);
	glLightxv(light, pname, params);
}
Exemplo n.º 4
0
/*!
* \brief	Updates the OpenGL ES state
* \param	width	Rendering width.
* \param	height	Rendering height.
*//*-------------------------------------------------------------------*/
static void updateOpenGLESState(int width, int height)
{
    /* Define lights and materials for the OpenGL ES scene */
    static const GLfixed light_position[]	= { F2F(-50.f), F2F(50.f), F2F(50.f), F2F(0.0f) };
    static const GLfixed light_ambient[]	= { F2F(0.125f), F2F(0.125f), F2F(0.125f), F2F(1.0f) };
    static const GLfixed light_diffuse[]	= { F2F(0.7f), F2F(0.7f), F2F(0.7f), F2F(1.0f) };
    static const GLfixed material_spec[]	= { F2F(0.7f), F2F(0.7f), F2F(0.7f), F2F(0.0f) };
    static const GLfixed zero_vec4[]		= { F2F(0.0f), F2F(0.0f), F2F(0.0f), F2F(0.0f) };

    /* Define the aspect ratio for the perpective calculations so that 
    no distortion happens when the screen is resized */
    float aspect		= height ? (float)width/(float)height : 1.0f;

    glViewport			(0, 0, width, height);
    glScissor			(0, 0, width, height);

    /* Set the matrix mode to world coordinates */
    glMatrixMode		(GL_MODELVIEW);
    glLoadIdentity		();

    /* Setup lights and materials with the values given above */
    glLightxv			(GL_LIGHT0, GL_POSITION, light_position);
    glLightxv			(GL_LIGHT0, GL_AMBIENT, light_ambient);
    glLightxv			(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    glLightxv			(GL_LIGHT0, GL_SPECULAR, zero_vec4);
    glMaterialxv		(GL_FRONT_AND_BACK, GL_SPECULAR, material_spec);

    /* Enable ligting, materials, backface culling and textures */
    glDisable			(GL_NORMALIZE);
    glEnable			(GL_LIGHTING);
    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ZERO);
    
    glEnable			(GL_LIGHT0);
    glEnable			(GL_COLOR_MATERIAL);
    glEnable			(GL_CULL_FACE);
    glEnable			(GL_TEXTURE_2D);

    /* Tell OpenGL to use nicest perspective correction */
    glHint				(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    /* Use flat shading and disable dithering */
    glShadeModel		(GL_FLAT);
    glDisable			(GL_DITHER);

    /* Setup the clear color and the current color for the OpenGL context */
    glClearColorx		(F2F(0.1f), F2F(0.2f), F2F(0.4f), F2F(1.f));
    glColor4x			(0x10000, 0x10000, 0x10000, 0x10000);

    /* Enable the use of vertex, normal and texture coordinate arrays */
    glEnableClientState	(GL_VERTEX_ARRAY);
    glEnableClientState	(GL_NORMAL_ARRAY);
    glEnableClientState	(GL_TEXTURE_COORD_ARRAY);

    /* Mipmaps do not work on all BREW devices, so disable it */
/*    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);*/
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    /* Update the projection matrix */
    glMatrixMode		(GL_PROJECTION);
    glLoadIdentity		();
    setGLESperspective	(60.f, aspect, 0.1f, 100.f);
}