Skip to content

Commit

Permalink
Fix int underlow
Browse files Browse the repository at this point in the history
  • Loading branch information
EosBandi authored and meee1 committed Nov 12, 2024
1 parent 31e8733 commit bdfbe6e
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions Controls/OpenGLtest2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ static int generateTexture(Bitmap image)
}

static void ConvertColorSpace(BitmapData _data)
{
{
// bgra to rgba
var x = 0; var y = 0; var width = _data.Width; var height = _data.Height;
for (y = 0; y < height; y++)
Expand Down Expand Up @@ -295,7 +295,7 @@ static int CreateTexture(BitmapData data)
}
else
{
// No, it's not a power of 2. Turn of mips and set wrapping to clamp to edge
// No, it's not a power of 2. Turn of mips and set wrapping to clamp to edge
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
}
return texture;
Expand All @@ -310,7 +310,7 @@ static int FloorPowerOf2(int value)
{
var ans = Math.Log(value, 2);

return (int)Math.Pow(2, Math.Floor(ans));
return (int)Math.Pow(2, Math.Floor(ans));
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down Expand Up @@ -519,7 +519,7 @@ public void doPaint()
/*Console.WriteLine("cam: {0} {1} {2} lookat: {3} {4} {5}", (float) cameraX, (float) cameraY, (float) cameraZ,
(float) lookX,
(float) lookY, (float) lookZ);
*/
*/
modelMatrix = Matrix4.LookAt((float) cameraX, (float) cameraY, (float) cameraZ + 100f * 0,
(float) lookX, (float) lookY, (float) lookZ,
0, 0, 1);
Expand All @@ -539,7 +539,7 @@ public void doPaint()
GL.ClearColor(Color.CornflowerBlue);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit |
ClearBufferMask.AccumBufferBit);

// disable depth during terrain draw
GL.Disable(EnableCap.DepthTest);
GL.DepthFunc(DepthFunction.Lequal);
Expand Down Expand Up @@ -642,7 +642,7 @@ public void doPaint()
startindex + 1, startindex + 3, startindex + 2
});


wpmarker.Draw(projMatrix, modelMatrix);

wpmarker.Cleanup(true);
Expand Down Expand Up @@ -696,7 +696,7 @@ private double[] projectLocation(double[] oldpos)
var factor = 0.3;
return new double[]
{
oldpos[0] * factor + newpos[0] * (1.0 - factor),
oldpos[0] * factor + newpos[0] * (1.0 - factor),
oldpos[1] * factor + newpos[1] * (1.0 - factor),
oldpos[2] * factor + newpos[2] * (1.0 - factor)
};
Expand Down Expand Up @@ -758,7 +758,7 @@ private void generateTextures()
if (DateTime.Now.Second % 3 == 1)
CleanupOldTextures(tileArea);
}

//https://wiki.openstreetmap.org/wiki/Zoom_levels
var C = 2 * Math.PI * 6378137.000;
// horizontal distance by each tile square
Expand All @@ -775,6 +775,7 @@ private void generateTextures()
stile = C * Math.Cos(_center.Lat) / Math.Pow(2, tilearea.zoom);
pxstep = (int)(stile / 45);
pxstep = FloorPowerOf2(pxstep);
if (pxstep == int.MinValue) pxstep = 0;
if (pxstep == 0)
pxstep = 1;
foreach (var p in tilearea.points)
Expand Down Expand Up @@ -879,7 +880,7 @@ private void generateTextures()

private void Minimumtile(List<tileZoomArea> tileArea)
{
foreach (tileZoomArea tileZoomArea in tileArea.Reverse<tileZoomArea>())
foreach (tileZoomArea tileZoomArea in tileArea.Reverse<tileZoomArea>())
{
//GPoint centerPixel = Provider.Projection.FromLatLngToPixel(center, Zoom);
//var centerTileXYLocation = Provider.Projection.FromPixelToTileXY(centerPixel);
Expand Down Expand Up @@ -1669,9 +1670,9 @@ void main(void) {
}

GL.UseProgram(_program);
positionSlot = GL.GetAttribLocation(_program, "Position");
colorSlot = GL.GetAttribLocation(_program, "SourceColor");
texCoordSlot = GL.GetAttribLocation(_program, "TexCoordIn");
positionSlot = GL.GetAttribLocation(_program, "Position");
colorSlot = GL.GetAttribLocation(_program, "SourceColor");
texCoordSlot = GL.GetAttribLocation(_program, "TexCoordIn");
projectionSlot = GL.GetUniformLocation(_program, "Projection");
modelViewSlot = GL.GetUniformLocation(_program, "ModelView");
textureSlot = GL.GetUniformLocation(_program, "Texture");
Expand Down Expand Up @@ -1716,7 +1717,7 @@ public void Cleanup(bool nolock = false)
public void Dispose()
{
Cleanup();
}
}
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
Expand Down

0 comments on commit bdfbe6e

Please sign in to comment.