Skip to content

Commit

Permalink
Adds quad/triangle test case
Browse files Browse the repository at this point in the history
  • Loading branch information
JujuAdams committed Mar 6, 2022
1 parent 3768b5f commit 7a10053
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
26 changes: 26 additions & 0 deletions objects/oScene/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,32 @@ CardboardSpriteExt(sprHi, 1, 0, 160, 160, 5, 5, 0, 0, c_white, 1);
CardboardSpriteExt(sprHi, 1, -160, 0, 160, 5, 5, 0, -90, c_white, 1);
CardboardSpriteExt(sprHi, 1, 0, -160, 160, 5, 5, 0, 180, c_white, 1);

CardboardSpriteQuad(sprHi, 0,
-160, -800, 160,
160, -800, 160,
-160, -480, 0,
160, -480, 0,
c_aqua, 1);

CardboardSpriteTriangle(sprHi, 0,
160, -800, 160, 0, 0,
480, -800, 160, 1, 0,
160, -480, 0, 0, 1,
c_aqua, 1);

CardboardSpriteTriangle(sprHi, 0,
480, -800, 160, 1, 0,
160, -480, 0, 0, 1,
480, -480, 160, 1, 1,
c_aqua, 1);

CardboardSpriteQuad(sprHi, 0,
480, -480, 160,
480, -160, 160,
160, -480, 0,
160, -160, 0,
c_aqua, 1);

model = CardboardModelEnd();

//Define a handy draw function that we can call from oRenderer later
Expand Down
16 changes: 9 additions & 7 deletions scripts/CardboardSpriteQuad/CardboardSpriteQuad.gml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
/// @param x4 x-coordinate for the bottom-right corner of the texture
/// @param y4 y-coordinate for the bottom-right corner of the texture
/// @param z4 z-coordinate for the bottom-right corner of the texture
/// @param color Blend color for the sprite (c_white is "no blending")
/// @param alpha Blend alpha for the sprite (0 being transparent and 1 being 100% opacity)

function CardboardSpriteQuad(_sprite, _image, _x1, _y1, _z1, _x2, _y2, _z2, _x3, _y3, _z3, _x4, _y4, _z4)
function CardboardSpriteQuad(_sprite, _image, _x1, _y1, _z1, _x2, _y2, _z2, _x3, _y3, _z3, _x4, _y4, _z4, _color, _alpha)
{
var _flooredImage = floor(max(0, _image)) mod sprite_get_number(_sprite);
var _imageData = global.__cardboardTexturePageIndexMap[? __CARDBOARD_MAX_IMAGES*_sprite + _flooredImage];
Expand All @@ -40,13 +42,13 @@ function CardboardSpriteQuad(_sprite, _image, _x1, _y1, _z1, _x2, _y2, _z2, _x3,
//Add this sprite to the vertex buffer
var _vertexBuffer = global.__cardboardBatchVertexBuffer;

vertex_position_3d(_vertexBuffer, _x1, _y1, _z1); vertex_color(_vertexBuffer, c_white, 1.0); vertex_texcoord(_vertexBuffer, _u0, _v0);
vertex_position_3d(_vertexBuffer, _x2, _y2, _z2); vertex_color(_vertexBuffer, c_white, 1.0); vertex_texcoord(_vertexBuffer, _u1, _v0);
vertex_position_3d(_vertexBuffer, _x3, _y3, _z3); vertex_color(_vertexBuffer, c_white, 1.0); vertex_texcoord(_vertexBuffer, _u0, _v1);
vertex_position_3d(_vertexBuffer, _x1, _y1, _z1); vertex_color(_vertexBuffer, _color, _alpha); vertex_texcoord(_vertexBuffer, _u0, _v0);
vertex_position_3d(_vertexBuffer, _x2, _y2, _z2); vertex_color(_vertexBuffer, _color, _alpha); vertex_texcoord(_vertexBuffer, _u1, _v0);
vertex_position_3d(_vertexBuffer, _x3, _y3, _z3); vertex_color(_vertexBuffer, _color, _alpha); vertex_texcoord(_vertexBuffer, _u0, _v1);

vertex_position_3d(_vertexBuffer, _x2, _y2, _z2); vertex_color(_vertexBuffer, c_white, 1.0); vertex_texcoord(_vertexBuffer, _u1, _v0);
vertex_position_3d(_vertexBuffer, _x4, _y4, _z4); vertex_color(_vertexBuffer, c_white, 1.0); vertex_texcoord(_vertexBuffer, _u1, _v1);
vertex_position_3d(_vertexBuffer, _x3, _y3, _z3); vertex_color(_vertexBuffer, c_white, 1.0); vertex_texcoord(_vertexBuffer, _u0, _v1);
vertex_position_3d(_vertexBuffer, _x2, _y2, _z2); vertex_color(_vertexBuffer, _color, _alpha); vertex_texcoord(_vertexBuffer, _u1, _v0);
vertex_position_3d(_vertexBuffer, _x4, _y4, _z4); vertex_color(_vertexBuffer, _color, _alpha); vertex_texcoord(_vertexBuffer, _u1, _v1);
vertex_position_3d(_vertexBuffer, _x3, _y3, _z3); vertex_color(_vertexBuffer, _color, _alpha); vertex_texcoord(_vertexBuffer, _u0, _v1);

if (!global.__cardboardAutoBatching && !global.__cardboardBuildingModel) CardboardBatchForceSubmit();
}

0 comments on commit 7a10053

Please # to comment.