Ребята, подскажите в чём беда? Вот код главной программы, куда всё подключаю.
Код:
using System;
using System.Collections.Generic;
using Sce.PlayStation.Core;
using Sce.PlayStation.Core.Environment;
using Sce.PlayStation.Core.Graphics;
using Sce.PlayStation.Core.Input;
namespace DemoGame1
{
public class AppMain
{
private static GraphicsContext graphics;
private static Sprite Demo;
public static void Main (string[] args)
{
Initialize ();
while (true) {
SystemEvents.CheckEvents ();
Update ();
Render ();
}
}
public static void Initialize ()
{
// Set up the graphics system
graphics = new GraphicsContext ();
Texture2D t = new Texture2D("/Application/Assets/Demo.png", false);
Demo = new Sprite (graphics, t);
Demo.Position.X = 100;
Demo.Position.Y = 100;
}
public static void Update ()
{
// Query gamepad for current state
var gamePadData = GamePad.GetData (0);
}
public static void Render ()
{
// Clear the screen
graphics.SetClearColor (0.0f, 1.0f, 1.0f, 0.0f);
graphics.Clear ();
Demo.Render ();
// Present the screen
graphics.SwapBuffers ();
}
}
}
Вот код спрайта.
Код:
using System;
using System.Collections.Generic;
using Sce.PlayStation.Core;
using Sce.PlayStation.Core.Graphics;
using Sce.PlayStation.Core.Imaging;
namespace DemoGame1
{
public class Sprite
{
static ShaderProgram shaderProgram;
protected GraphicsContext graphics;
float[] vertices = new float[12];
const int indexSize = 4;
ushort[] indices;
VertexBuffer vertexBuffer;
protected Texture2D texture;
public Vector3 Position;
public Vector2 Center;
public Vector2 Scale = Vector2.One;
float width, height;
public float Width
{
get{return width * Scale.X;}
}
public float Height
{
get{return height * Scale.Y;}
}
public Sprite (GraphicsContext graphics, Texture2D texture)
{
if (shaderProgram == null)
{
shaderProgram = new ShaderProgram("/Application/shaders/Simple.cgx");
shaderProgram.SetUniformBinding(0, "u_WorldMatrix");
}
if (texture == null)
{
throw new Exception("ERROR: texture is null.");
}
this.graphics = graphics;
this.texture = texture;
this.width = texture.Width;
this.height = texture.Height;
indices = new ushort[indexSize];
indices[0] = 0;
indices[1] = 1;
indices[2] = 2;
indices[3] = 3;
vertexBuffer = new VertexBuffer(4, indexSize, VertexFormat.Float3, VertexFormat.Float2, VertexFormat.Float4);
}
public void Render()
{
vertices[0]=Position.X - Width * Center.X;
vertices[1]=Position.Y - Height * Center.Y;
vertices[2]=Position.Z;
vertices[3]=Position.X - Width * Center.X;
vertices[4]=Position.Y - Height * (1.0f-Center.Y);
vertices[5]=Position.Z;
vertices[6]=Position.X - width * (1.0f-Center.X);
vertices[7]=Position.Y - height * Center.Y;
vertices[8]=Position.Z;
vertices[9]=Position.X - width * (1.0f-Center.X);
vertices[10]=Position.Y - height * (1.0f-Center.Y);
vertices[11]=Position.Z;
Matrix4 screenMatrix = new Matrix4(
2.0f/graphics.Screen.Rectangle.Width, 0.0f, 0.0f, 0.0f,
0.0f, -2.0f/graphics.Screen.Rectangle.Height, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
-1.0f, 1.0f, 0.0f, 1.0f
);
graphics.SetTexture(0, texture);
shaderProgram.SetUniformValue(0, ref screenMatrix);
}
}
}
Это код шейдера.
Код:
void main( float4 in a_Position : POSITION,
float4 out v_Position : POSITION,
uniform float4x4 u_WorldMatrix
)
{
v_Position = mul( a_Position, u_WorldMatrix );
}
Добился, чтобы без ошибок было, но картинку не выводит.