Skip to content

Commit

Permalink
Merge pull request #595 from leezer3/OpenGLMenu
Browse files Browse the repository at this point in the history
New: OpenGL Main Menu (for systems not supporting WinForms)
  • Loading branch information
leezer3 authored Jul 20, 2021
2 parents cb9acfb + 304df79 commit 91bedcb
Show file tree
Hide file tree
Showing 87 changed files with 2,804 additions and 991 deletions.
15 changes: 15 additions & 0 deletions assets/Languages/en-US.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<trans-unit id="fullscreen_switch2">
<source>Please check your fullscreen resolution settings.</source>
</trans-unit>
<trans-unit id="route_please_select">
<source>Please first select a route file to begin.</source>
</trans-unit>
<trans-unit id="route_corrupt_withtrack">
<source>The selected route is corrupt: \r\n WithTrack section missing.</source>
</trans-unit>
Expand Down Expand Up @@ -209,6 +212,18 @@
<trans-unit id="train">
<source>Train</source>
</trans-unit>
<trans-unit id="train_choose">
<source>Choose Train...</source>
</trans-unit>
<trans-unit id="train_default">
<source>Do you wish to use the default train?</source>
</trans-unit>
<trans-unit id="train_default_no">
<source>No</source>
</trans-unit>
<trans-unit id="train_default_yes">
<source>Yes</source>
</trans-unit>
<trans-unit id="train_selection">
<source>Selection</source>
</trans-unit>
Expand Down
Binary file modified assets/Menu/icon_disk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/Menu/icon_folder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/Menu/icon_route.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/Menu/icon_train.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Menu/please_select.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 39 additions & 10 deletions assets/Shaders/default.frag
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#version 150

#version 150 core
in vec4 oViewPos;
in vec2 oUv;
in vec4 oColor;
in vec4 oLightResult;

uniform bool uIsTexture;
uniform int uAlphaFunction;
uniform float uAlphaComparison;
uniform sampler2D uTexture;
uniform int uMaterialFlags;
uniform float uBrightness;
Expand All @@ -16,14 +15,12 @@ uniform float uFogEnd;
uniform vec3 uFogColor;
uniform float uFogDensity;
uniform bool uFogIsLinear;
out vec4 fragColor;

void main(void)
{
vec4 finalColor = vec4(oColor.rgb, 1.0);
if(uIsTexture)
{
finalColor *= texture2D(uTexture, oUv);
}
vec4 finalColor = vec4(oColor.rgb, 1.0) * texture(uTexture, oUv);

if((uMaterialFlags & 1) == 0 && (uMaterialFlags & 4) == 0)
{
//Material is not emissive and lighting is enabled, so multiply by brightness
Expand All @@ -33,6 +30,38 @@ void main(void)
//Apply the lighting results *after* the final color has been calculated
finalColor *= oLightResult;

/*
* NOTES:
* Unused alpha functions must not be added to the shader
* This has a nasty affect on framerates
*
* A switch case block is also ~30% slower than the else-if
*
* Numbers used are those from the GL.AlphaFunction enum to allow
* for direct casts
*/
if(uAlphaFunction == 513) // Less
{
if(finalColor.a >= uAlphaComparison)
{
discard;
}
}
else if(uAlphaFunction == 514) // Equal
{
if(!(abs(finalColor.a - 1.0) < 0.00001))
{
discard;
}
}
else if(uAlphaFunction == 516) // Greater
{
if(finalColor.a <= uAlphaComparison)
{
discard;
}
}

// Fog
float fogFactor = 1.0;

Expand All @@ -48,5 +77,5 @@ void main(void)
}
}

gl_FragData[0] = vec4(mix(uFogColor, finalColor.rgb, fogFactor), finalColor.a);
fragColor = vec4(mix(uFogColor, finalColor.rgb, fogFactor), finalColor.a);
}
2 changes: 1 addition & 1 deletion assets/Shaders/default.vert
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 150
#version 150 core
precision highp int;

struct Light
Expand Down
6 changes: 3 additions & 3 deletions assets/Shaders/picking.frag
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#version 150

#version 150 core
uniform int uObjectIndex;
out vec4 fragColor;

void main(void)
{
gl_FragData[0].r = float(uObjectIndex);
fragColor.r = float(uObjectIndex);
}
50 changes: 50 additions & 0 deletions assets/Shaders/rectangle.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#version 150 core
in vec2 textureCoord;
uniform int uAlphaFunction;
uniform float uAlphaComparison;
uniform bool uRectangleHasColour;
uniform vec4 uColor;
uniform sampler2D uTexture;
out vec4 fragColor;

void main(void)
{
vec4 textureColour = texture(uTexture, textureCoord);

vec4 finalColor = textureColour * uColor;

/*
* NOTES:
* Unused alpha functions must not be added to the shader
* This has a nasty affect on framerates
*
* A switch case block is also ~30% slower than the else-if
*
* Numbers used are those from the GL.AlphaFunction enum to allow
* for direct casts
*/
if(uAlphaFunction == 513) // Less
{
if(finalColor.a >= uAlphaComparison)
{
discard;
}
}
else if(uAlphaFunction == 514) // Equal
{
if(!(abs(finalColor.a - 1.0) < 0.00001))
{
discard;
}
}
else if(uAlphaFunction == 516) // Greater
{
if(finalColor.a <= uAlphaComparison)
{
discard;
}
}

fragColor = finalColor;

}
44 changes: 44 additions & 0 deletions assets/Shaders/rectangle.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#version 150 core
uniform mat4 uCurrentProjectionMatrix;
uniform mat4 uCurrentModelViewMatrix;
uniform vec2 uPoint;
uniform vec2 uSize;
uniform vec2 uCoordinates;
out vec2 textureCoord;
vec4 viewPos = vec4(0,0,0,0);

void main()
{
if(gl_VertexID == 0)
{
viewPos = uCurrentModelViewMatrix * vec4(vec3(uPoint.x, uPoint.y, 0), 1.0);
textureCoord = vec2(0,0);
}
else if (gl_VertexID == 1)
{
viewPos = uCurrentModelViewMatrix * vec4(vec3(uPoint.x + uSize.x, uPoint.y, 0), 1.0);
textureCoord = vec2(uCoordinates.x,0);
}
else if (gl_VertexID == 2)
{
viewPos = uCurrentModelViewMatrix * vec4(vec3(uPoint.x + uSize.x, uPoint.y + uSize.y, 0), 1.0);
textureCoord = uCoordinates;
}
else if (gl_VertexID == 3)
{
viewPos = uCurrentModelViewMatrix * vec4(vec3(uPoint.x, uPoint.y, 0), 1.0);
textureCoord = vec2(0,0);
}
else if (gl_VertexID == 4)
{
viewPos = uCurrentModelViewMatrix * vec4(vec3(uPoint.x, uPoint.y + uSize.y, 0), 1.0);
textureCoord = vec2(0, uCoordinates.y);
}
else if (gl_VertexID == 5)
{
viewPos = uCurrentModelViewMatrix * vec4(vec3(uPoint.x + uSize.x, uPoint.y + uSize.y, 0), 1.0);
textureCoord = uCoordinates;
}

gl_Position = uCurrentProjectionMatrix * viewPos;
}
41 changes: 41 additions & 0 deletions assets/Shaders/text.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#version 150 core

uniform mat4 uCurrentProjectionMatrix;
uniform mat4 uCurrentModelViewMatrix;
uniform vec2 uPoint;
uniform vec2 uSize;
uniform vec4 uAtlasLocation;
out vec2 textureCoord;
vec4 viewPos = vec4(0,0,0,0);

void main()
{
switch(gl_VertexID)
{
case 0:
viewPos = uCurrentModelViewMatrix * vec4(vec3(uPoint.x, uPoint.y, 0), 1.0);
textureCoord = vec2(uAtlasLocation.x, uAtlasLocation.y);
break;
case 1:
viewPos = uCurrentModelViewMatrix * vec4(vec3(uPoint.x + uSize.x, uPoint.y, 0), 1.0);
textureCoord = vec2(uAtlasLocation.x + uAtlasLocation.z, uAtlasLocation.y);
break;
case 2:
viewPos = uCurrentModelViewMatrix * vec4(vec3(uPoint.x + uSize.x, uPoint.y + uSize.y, 0), 1.0);
textureCoord = vec2(uAtlasLocation.x + uAtlasLocation.z, uAtlasLocation.y + uAtlasLocation.w);
break;
case 3:
viewPos = uCurrentModelViewMatrix * vec4(vec3(uPoint.x, uPoint.y, 0), 1.0);
textureCoord = vec2(uAtlasLocation.x, uAtlasLocation.y);
break;
case 4:
viewPos = uCurrentModelViewMatrix * vec4(vec3(uPoint.x, uPoint.y + uSize.y, 0), 1.0);
textureCoord = vec2(uAtlasLocation.x, uAtlasLocation.y + uAtlasLocation.w);
break;
case 5:
viewPos = uCurrentModelViewMatrix * vec4(vec3(uPoint.x + uSize.x, uPoint.y + uSize.y, 0), 1.0);
textureCoord = vec2(uAtlasLocation.x + uAtlasLocation.z, uAtlasLocation.y + uAtlasLocation.w);
break;
}
gl_Position = uCurrentProjectionMatrix * viewPos;
}
Binary file modified installers/mac/MacBundle.tgz
Binary file not shown.
19 changes: 3 additions & 16 deletions source/LibRender2/Backgrounds/Background.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using OpenBveApi.Math;
using OpenBveApi.Objects;
using OpenBveApi.Routes;
Expand Down Expand Up @@ -133,8 +133,6 @@ private void RenderStaticBackgroundRetained(StaticBackground data, float alpha,
if (data.Texture != null && renderer.currentHost.LoadTexture(data.Texture, OpenGlTextureWrapMode.RepeatClamp))
{
renderer.LastBoundTexture = data.Texture.OpenGlTextures[(int)OpenGlTextureWrapMode.RepeatClamp];
GL.Enable(EnableCap.Texture2D);

if (alpha == 1.0f)
{
GL.Disable(EnableCap.Blend);
Expand Down Expand Up @@ -164,7 +162,6 @@ private void RenderStaticBackgroundRetained(StaticBackground data, float alpha,
}

// texture
renderer.DefaultShader.SetIsTexture(true);
GL.BindTexture(TextureTarget.Texture2D, data.Texture.OpenGlTextures[(int)OpenGlTextureWrapMode.RepeatClamp].Name);
renderer.LastBoundTexture = null;

Expand All @@ -178,15 +175,10 @@ private void RenderStaticBackgroundRetained(StaticBackground data, float alpha,
VertexArrayObject VAO = (VertexArrayObject)data.VAO;
VAO.Bind();
renderer.lastVAO = VAO.handle;
for (int i = 0; i + 9 < 32 * 10; i += 10)
for (int i = 0; i + 11 < 32 * 12; i += 12)
{
VAO.Draw(PrimitiveType.Quads, i, 4);
VAO.Draw(PrimitiveType.Triangles, i + 4, 3);
VAO.Draw(PrimitiveType.Triangles, i + 7, 3);
VAO.Draw(PrimitiveType.Triangles, i, 12);
}
renderer.DefaultShader.Deactivate();

GL.Disable(EnableCap.Texture2D);
renderer.RestoreBlendFunc();
}
}
Expand Down Expand Up @@ -373,11 +365,6 @@ private void RenderBackgroundObject(BackgroundObject data)
renderer.RenderFaceImmediateMode(new ObjectState(data.Object), face, Matrix4D.NoTransformation, Matrix4D.Scale(1.0) * renderer.CurrentViewMatrix);
}
}

if (renderer.AvailableNewRenderer)
{
renderer.DefaultShader.Deactivate();
}
}
}
}
Loading

0 comments on commit 91bedcb

Please sign in to comment.