mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-22 17:12:25 -05:00
Picking use shaders.
This commit is contained in:
parent
fbb3aa2393
commit
d30c6fb148
2 changed files with 33 additions and 24 deletions
|
@ -206,6 +206,7 @@ namespace ClassicalSharp {
|
|||
const double imageCheckPeriod = 30.0;
|
||||
double ticksAccumulator = 0, imageCheckAccumulator = 0;
|
||||
|
||||
internal Matrix4 mvp;
|
||||
protected override void OnRenderFrame( FrameEventArgs e ) {
|
||||
accumulator += e.Time;
|
||||
imageCheckAccumulator += e.Time;
|
||||
|
@ -244,6 +245,7 @@ namespace ClassicalSharp {
|
|||
Graphics.SetMatrixMode( MatrixType.Modelview );
|
||||
Matrix4 modelView = Camera.GetView();
|
||||
View = modelView;
|
||||
mvp = modelView * Projection;
|
||||
Graphics.LoadMatrix( ref modelView );
|
||||
Culling.CalcFrustumEquations( ref Projection, ref modelView );
|
||||
|
||||
|
|
|
@ -8,21 +8,20 @@ namespace ClassicalSharp.Renderers {
|
|||
|
||||
Game window;
|
||||
OpenGLApi graphics;
|
||||
PickingShader shader;
|
||||
|
||||
public PickingRenderer( Game window ) {
|
||||
this.window = window;
|
||||
graphics = window.Graphics;
|
||||
shader = new PickingShader();
|
||||
shader.Initialise( graphics );
|
||||
}
|
||||
|
||||
FastColour col = FastColour.White;
|
||||
double accumulator;
|
||||
|
||||
int index = 0;
|
||||
VertexPos3fCol4b[] vertices = new VertexPos3fCol4b[24 * ( 3 * 2 )];
|
||||
Vector3[] vertices = new Vector3[24 * ( 3 * 2 )];
|
||||
const float size = 0.0625f;
|
||||
const float offset = 0.01f;
|
||||
public void Render( double delta ) {
|
||||
accumulator += delta;
|
||||
index = 0;
|
||||
PickedPos pickedPos = window.SelectedPos;
|
||||
|
||||
|
@ -60,38 +59,46 @@ namespace ClassicalSharp.Renderers {
|
|||
DrawZPlane( max.Z + offset, max.X + offset, min.Y - offset, max.X - size + offset, max.Y + offset );
|
||||
DrawZPlane( max.Z + offset, min.X - offset, min.Y - offset, max.X + offset, min.Y + size - offset );
|
||||
DrawZPlane( max.Z + offset, min.X - offset, max.Y + offset, max.X + offset, max.Y - size + offset );
|
||||
graphics.DrawVertices( DrawMode.Triangles, vertices, vertices.Length );
|
||||
|
||||
graphics.UseProgram( shader.ProgramId );
|
||||
graphics.SetUniform( shader.mvpLoc, ref window.mvp );
|
||||
graphics.BeginDrawClientVertices( DrawMode.Triangles );
|
||||
for( int i = 0; i < vertices.Length; i++ ) {
|
||||
graphics.SetVertexAttrib( shader.positionLoc, vertices[i] );
|
||||
}
|
||||
graphics.EndDrawClientVertices();
|
||||
graphics.UseProgram( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
void DrawXPlane( float x, float z1, float y1, float z2, float y2 ) {
|
||||
vertices[index++] = new VertexPos3fCol4b( x, y1, z1, col );
|
||||
vertices[index++] = new VertexPos3fCol4b( x, y2, z1, col );
|
||||
vertices[index++] = new VertexPos3fCol4b( x, y2, z2, col );
|
||||
vertices[index++] = new Vector3( x, y1, z1 );
|
||||
vertices[index++] = new Vector3( x, y2, z1 );
|
||||
vertices[index++] = new Vector3( x, y2, z2 );
|
||||
|
||||
vertices[index++] = new VertexPos3fCol4b( x, y2, z2, col );
|
||||
vertices[index++] = new VertexPos3fCol4b( x, y1, z2, col );
|
||||
vertices[index++] = new VertexPos3fCol4b( x, y1, z1, col );
|
||||
vertices[index++] = new Vector3( x, y2, z2 );
|
||||
vertices[index++] = new Vector3( x, y1, z2 );
|
||||
vertices[index++] = new Vector3( x, y1, z1 );
|
||||
}
|
||||
|
||||
void DrawZPlane( float z, float x1, float y1, float x2, float y2 ) {
|
||||
vertices[index++] = new VertexPos3fCol4b( x1, y1, z, col );
|
||||
vertices[index++] = new VertexPos3fCol4b( x1, y2, z, col );
|
||||
vertices[index++] = new VertexPos3fCol4b( x2, y2, z, col );
|
||||
vertices[index++] = new Vector3( x1, y1, z );
|
||||
vertices[index++] = new Vector3( x1, y2, z );
|
||||
vertices[index++] = new Vector3( x2, y2, z );
|
||||
|
||||
vertices[index++] = new VertexPos3fCol4b( x2, y2, z, col );
|
||||
vertices[index++] = new VertexPos3fCol4b( x2, y1, z, col );
|
||||
vertices[index++] = new VertexPos3fCol4b( x1, y1, z, col );
|
||||
vertices[index++] = new Vector3( x2, y2, z );
|
||||
vertices[index++] = new Vector3( x2, y1, z );
|
||||
vertices[index++] = new Vector3( x1, y1, z );
|
||||
}
|
||||
|
||||
void DrawYPlane( float y, float x1, float z1, float x2, float z2 ) {
|
||||
vertices[index++] = new VertexPos3fCol4b( x1, y, z1, col );
|
||||
vertices[index++] = new VertexPos3fCol4b( x1, y, z2, col );
|
||||
vertices[index++] = new VertexPos3fCol4b( x2, y, z2, col );
|
||||
vertices[index++] = new Vector3( x1, y, z1 );
|
||||
vertices[index++] = new Vector3( x1, y, z2 );
|
||||
vertices[index++] = new Vector3( x2, y, z2 );
|
||||
|
||||
vertices[index++] = new VertexPos3fCol4b( x2, y, z2, col );
|
||||
vertices[index++] = new VertexPos3fCol4b( x2, y, z1, col );
|
||||
vertices[index++] = new VertexPos3fCol4b( x1, y, z1, col );
|
||||
vertices[index++] = new Vector3( x2, y, z2 );
|
||||
vertices[index++] = new Vector3( x2, y, z1 );
|
||||
vertices[index++] = new Vector3( x1, y, z1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue