// Project: triangle
// Created: 2018-03-03
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "triangle" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
//first we will create a memblock to hold the mesh
memblock = CreateMemblock(160)
//Now we need to fill it with mesh data
SetMemblockInt(memblock,0,3) //3 vertices
SetMemblockInt(memblock,4,3) //3 indices, not necissary for simple triangle, but we do it here for completeness
SetMemblockint(memblock,8,3) //Our mesh has 3 attributes, position, normal, color
Setmemblockint(memblock,12,28) //number of bytes each vertext takes up. x,y,z,nx,ny,nz,color * 4
SetMemblockInt(memblock,16,64) //offset to vertex data
SetMemblockInt(memblock,20,148) //offset to index data
//Attribute information, I'm combining all bytes into a single int.
// Little endiness means order is string length, normal flag, component count, data type (data will
// be written to the MemBlock in reverse order).
SetMemBlockInt(memblock,24,0x0C000300) //float, 3 components, no normalizing, position
SetMemblockString(memblock,28,"position")
SetMemblockInt(memblock,40,0x08000300) //same as position, but for normals
SetMemblockString(memblock,44,"normal")
SetMemblockInt(memblock,52,0x08010401) //For color we have byte, 4 components, normalize data
SetMemblockString(memblock,56,"color")
//Now we can enter vertex data
Vertex as float[8] = [5.0,-5.0,0.0,-5.0,-5.0,0.0,0.0,5.0,0.0]
Color as integer[2] = [0xFFFF0000,0xFF00FF00,0xFF0000FF]
for i = 0 to 2
SetMemblockFloat(memblock,64+i*28,Vertex[i*3]) //x
SetMemblockFloat(memblock,68+i*28,Vertex[i*3+1]) //y
SetMemblockFloat(memblock,72+i*28,Vertex[i*3+2]) //z
SetMemblockFloat(memblock,76+i*28,0.0) //nx
SetMemblockFloat(memblock,80+i*28,0.0) //ny
SetMemblockFloat(memblock,84+i*28,-1.0) //nz
SetMemblockInt(memblock,88+i*28,Color[i]) //color
next
// Now the index data
SetMemblockInt(memblock,148,0)
SetMemblockInt(memblock,152,2)
SetMemblockInt(memblock,156,1)
//Now to create the object
triangle = CreateObjectFromMeshMemblock(memblock)
do
Print( ScreenFPS() )
Sync()
loop
Help make AGK better by submitting an example for this command! (All examples are subject to approval)