Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Do not set light parameters every frame (except Sun position). Fix bug

with light parameters not being reset between games. Closes ticket:3952
  • Loading branch information...
commit d69f336ec4bbe7b3c9b9207a09c01dcd797f6f77 1 parent def1e4f
Per Inge Mathisen authored February 18, 2013
4  data/mp/multiplay/skirmish/semperfi.js
@@ -747,4 +747,8 @@ function eventChat(from, to, message)
747 747
 	{
748 748
 		donatePower(playerPower(me) / 2, from);
749 749
 	}
  750
+	else if (message == "crazycolours")
  751
+	{
  752
+		setSunIntensity(0.6, 0.4, 0.3,  1.0, 0.8, 0.7,  1.2, 0.9, 0.8);
  753
+	}
750 754
 }
4  lib/ivis_opengl/piedef.h
@@ -82,6 +82,10 @@ extern void pie_GetResetCounts(unsigned int* pPieCount, unsigned int* pPolyCount
82 82
 /** Setup stencil shadows and OpenGL lighting. */
83 83
 void pie_BeginLighting(const Vector3f * light, bool drawshadows);
84 84
 
  85
+/** Set light parameters */
  86
+void pie_InitLighting();
  87
+void pie_SetupLighting();
  88
+
85 89
 /* Stop using stencil shadows and OpenGL lighting (if enabled). */
86 90
 void pie_EndLighting(void);
87 91
 
30  lib/ivis_opengl/piedraw.cpp
@@ -59,12 +59,28 @@ static GLenum ss_op_depth_pass_back = GL_DECR;
59 59
 static unsigned int pieCount = 0;
60 60
 static unsigned int polyCount = 0;
61 61
 static bool shadows = false;
62  
-static GLfloat lighting0[LIGHT_MAX][4] = {{0.0f, 0.0f, 0.0f, 1.0f},  {0.5f, 0.5f, 0.5f, 1.0f},  {0.8f, 0.8f, 0.8f, 1.0f},  {1.0f, 1.0f, 1.0f, 1.0f}};
  62
+static GLfloat lighting0[LIGHT_MAX][4];
63 63
 
64 64
 /*
65 65
  *	Source
66 66
  */
67 67
 
  68
+void pie_InitLighting()
  69
+{
  70
+	const GLfloat defaultLight[LIGHT_MAX][4] = {{0.0f, 0.0f, 0.0f, 1.0f},  {0.5f, 0.5f, 0.5f, 1.0f},  {0.8f, 0.8f, 0.8f, 1.0f},  {1.0f, 1.0f, 1.0f, 1.0f}};
  71
+	memcpy(lighting0, defaultLight, sizeof(lighting0));
  72
+	pie_SetupLighting();
  73
+}
  74
+
  75
+void pie_SetupLighting()
  76
+{
  77
+	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lighting0[LIGHT_EMISSIVE]);
  78
+	glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
  79
+	glLightfv(GL_LIGHT0, GL_AMBIENT, lighting0[LIGHT_AMBIENT]);
  80
+	glLightfv(GL_LIGHT0, GL_DIFFUSE, lighting0[LIGHT_DIFFUSE]);
  81
+	glLightfv(GL_LIGHT0, GL_SPECULAR, lighting0[LIGHT_SPECULAR]);
  82
+}
  83
+
68 84
 void pie_Lighting0(LIGHTING_TYPE entry, float value[4])
69 85
 {
70 86
 	lighting0[entry][0] = value[0];
@@ -75,14 +91,9 @@ void pie_Lighting0(LIGHTING_TYPE entry, float value[4])
75 91
 
76 92
 void pie_BeginLighting(const Vector3f *light, bool drawshadows)
77 93
 {
78  
-	const float pos[4] = {light->x, light->y, light->z, 0.0f};
  94
+	const float pos[4] = { light->x, light->y, light->z, 0.0f };
79 95
 
80  
-	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lighting0[LIGHT_EMISSIVE]);
81  
-	glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
82 96
 	glLightfv(GL_LIGHT0, GL_POSITION, pos);
83  
-	glLightfv(GL_LIGHT0, GL_AMBIENT, lighting0[LIGHT_AMBIENT]);
84  
-	glLightfv(GL_LIGHT0, GL_DIFFUSE, lighting0[LIGHT_DIFFUSE]);
85  
-	glLightfv(GL_LIGHT0, GL_SPECULAR, lighting0[LIGHT_SPECULAR]);
86 97
 	glEnable(GL_LIGHT0);
87 98
 
88 99
 	if (drawshadows)
@@ -91,11 +102,6 @@ void pie_BeginLighting(const Vector3f *light, bool drawshadows)
91 102
 	}
92 103
 }
93 104
 
94  
-bool pie_GetLightingState(void)
95  
-{
96  
-	return true;
97  
-}
98  
-
99 105
 void pie_EndLighting(void)
100 106
 {
101 107
 	shadows = false;
1  src/init.cpp
@@ -1094,6 +1094,7 @@ bool stageThreeInitialise(void)
1094 1094
 
1095 1095
 	effectResetUpdates();
1096 1096
 	initLighting(0, 0, mapWidth, mapHeight);
  1097
+	pie_InitLighting();
1097 1098
 
1098 1099
 	if(bMultiPlayer)
1099 1100
 	{
1  src/qtscriptfuncs.cpp
@@ -3669,6 +3669,7 @@ static QScriptValue js_setSunIntensity(QScriptContext *context, QScriptEngine *)
3669 3669
 	pie_Lighting0(LIGHT_AMBIENT, ambient);
3670 3670
 	pie_Lighting0(LIGHT_DIFFUSE, diffuse);
3671 3671
 	pie_Lighting0(LIGHT_SPECULAR, specular);
  3672
+	pie_SetupLighting();
3672 3673
 	return QScriptValue();
3673 3674
 }
3674 3675
 
1  src/scriptfuncs.cpp
@@ -260,6 +260,7 @@ bool scrSetSunIntensity(void)
260 260
 	pie_Lighting0(LIGHT_AMBIENT, ambient);
261 261
 	pie_Lighting0(LIGHT_DIFFUSE, diffuse);
262 262
 	pie_Lighting0(LIGHT_SPECULAR, specular);
  263
+	pie_SetupLighting();
263 264
 	return true;
264 265
 }
265 266
 

0 notes on commit d69f336

Please sign in to comment.
Something went wrong with that request. Please try again.