• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

DrawPrimitives

RaspberryDJ

New member
Joined
Jun 3, 2019
Messages
122
Any help on this one? There's no examples it seems.
I noticed there are commands especially meant for batching graphics called

DrawIndexedPrimitives and DrawPrimitives

There are examples how to draw solid coloured quads but how would you to draw multiple quads with graphics? :)
 
There are no examples? :eek:

I'm sure I have something. I'll report back
 
I want to know how to draw actually images using DrawIndexedPrimitives and DrawPrimitives
and also learn what makes each of these too special (what does index mean?)
 
But you don't load a png in that sourcecode? You load vector from txt tile, it's just coloured quads?
Actually it's polygons triangulated to allow concave shapes.
To draw images you need to set the texurecoords and provide a material. As I recall, there used to be a Monkey-x example, so if the achieves are alive somewhere, you could maybe find that.
 
Actually it's polygons triangulated to allow concave shapes.
To draw images you need to set the texurecoords and provide a material. As I recall, there used to be a Monkey-x example, so if the achieves are alive somewhere, you could maybe find that.

Sounds like that's what I want, I've searched for a few months now. I can't find any?
 
Okay I searching for the simplest so I think I'm looking for some code to draw any image as 10 separate quads in one command. It should be doing the same as 10 simple DrawImage instructions, let's say. That's what I could work with and begin to understand how it works.
 
What do you mean? Oh I explained poorly I'm so sorry.
I don't have anything. I begin on a blank space and want to teach myself the graphical commands that are called in the manual :

"DrawIndexedPrimitives" and "DrawPrimitives"

I dot not know how to use them.
 
AMOS2 has released maybe there's a helpful community there. Here you keep everything good for yourself apparently.
 
I don't quite get where you're coming from, I'm a very infrequent visitor to this site.
That said, I'd like to help if you post some code.
 
okay?
Well.. I just told you that I've tried to find information by myself for *MONTHS* without wanting to ask anthing. Becuase THIS HAPPENS. I thought.. maybe.. maybe I ask just once maybe I can ask somethings small which would help in big ways if I just get the right push.
 
It's easier to start with DrawPrimitives() - you feed it:
1. order - how many "vertices" shall be used per primitive
2. count - how many primitives shall be drawn
3. vertices - the x/y screen coordinates of your vertices provided as continuous float array, e.g. [x0,y0, x1,y1, x2,y2, x3,y,3]
4. texcoords - the s/t texture coordinates (sometimes also called u/v) of your vertices, also provided as continuous float array. Texture coordinates go from 0,0 (top left corner of your texture) to 1,1 (bottom right corner of your texture)
5. material - material, from which the texture and shader data is extracted. You can load an image file as Material (using Material.load()) or access an Image's material by the image.Material() property.

Something like this should work (untested, I don't have access to CX right now):

Cerberus:
Local material:Material = Material.load("myfile.png", 0)

' where to draw
Local x1:Float = 32
Local x2:Float = x1 + 64
Local y1:Float = 32
Local y2:Float = y1 + 64
' provide four vertices from those coordinates as array
Local verts:Float[] = [x1,y1, x2,y1, x2,y2, x1,y2]
' piece of texture to draw
Local s1:Float = 0
Local s2:Float = 0.5
Local t1:Float = 0
Local t2:Float = 0.5
' provide texture coordinates for vertices
Local texcs:Float[] = [s1,t1, s2,t1, s2,t2, s1,t2]
' draw one quad (1 primitive consisting of 4 vertices)
mycanvas.DrawPrimitives(4, 1, verts, texcs, material)

Pretty straight forward. The twist with DrawIndexedPrimitives is that it allows you to reuse vertices. E.g: you can feed it 6 vertex coordinate pairs (in xy and st each) and tell it, with the indices, which pairs to use, like
verts:Float[] = [x1,y1, x2,y1, x3,y1, x1,y2, x2,y2, x3,y3]
idxs:Int[] = [0, 1, 4, 3]
(and order=4, count=1)
would draw a quad from x1,x1 - x2,y1 - x2,y2 - x1,y2 (you'll find these pairs at given indexes in verts[])
 
What do you mean? Oh I explained poorly I'm so sorry.
I don't have anything. I begin on a blank space and want to teach myself the graphical commands that are called in the manual :

"DrawIndexedPrimitives" and "DrawPrimitives"

I dot not know how to use them.

DrawIndexedPrimitives() is used in the 'VectorMonkey' morphing example that ships with CX. I tidied up the original code but it's still not a great example and there are next to no comments.

A better, simple example like the code @Holzchopf posted would be a good inclusion to CX :D


 
It's easier to start with DrawPrimitives() - you feed it:
1. order - how many "vertices" shall be used per primitive
2. count - how many primitives shall be drawn
3. vertices - the x/y screen coordinates of your vertices provided as continuous float array, e.g. [x0,y0, x1,y1, x2,y2, x3,y,3]
4. texcoords - the s/t texture coordinates (sometimes also called u/v) of your vertices, also provided as continuous float array. Texture coordinates go from 0,0 (top left corner of your texture) to 1,1 (bottom right corner of your texture)
5. material - material, from which the texture and shader data is extracted. You can load an image file as Material (using Material.load()) or access an Image's material by the image.Material() property.

Something like this should work (untested, I don't have access to CX right now):

Cerberus:
Local material:Material = Material.load("myfile.png", 0)

' where to draw
Local x1:Float = 32
Local x2:Float = x1 + 64
Local y1:Float = 32
Local y2:Float = y1 + 64
' provide four vertices from those coordinates as array
Local verts:Float[] = [x1,y1, x2,y1, x2,y2, x1,y2]
' piece of texture to draw
Local s1:Float = 0
Local s2:Float = 0.5
Local t1:Float = 0
Local t2:Float = 0.5
' provide texture coordinates for vertices
Local texcs:Float[] = [s1,t1, s2,t1, s2,t2, s1,t2]
' draw one quad (1 primitive consisting of 4 vertices)
mycanvas.DrawPrimitives(4, 1, verts, texcs, material)

Pretty straight forward. The twist with DrawIndexedPrimitives is that it allows you to reuse vertices. E.g: you can feed it 6 vertex coordinate pairs (in xy and st each) and tell it, with the indices, which pairs to use, like
verts:Float[] = [x1,y1, x2,y1, x3,y1, x1,y2, x2,y2, x3,y3]
idxs:Int[] = [0, 1, 4, 3]
(and order=4, count=1)
would draw a quad from x1,x1 - x2,y1 - x2,y2 - x1,y2 (you'll find these pairs at given indexes in verts[])

Thanks for the explanation, it was a really helpful!

But do you have to use floating point now to set coordinates you can't use pixels anymore?
I was thinking to try speed up a draw of 10.000 tiny tiles and see if they draw faster using these commands, rather than what I do now which is a simple loop of DRAWAIMAGE or DRAWRECT instructions.
 
I was thinking to try speed up a draw of 10.000 tiny tiles and see if they draw faster using these commands, rather than what I do now which is a simple loop of DRAWAIMAGE or DRAWRECT instructions.

Oh this will definitely speed things up. And yes, it is quite a bit of brain work to get this stuff working. Pen and paper will help you a lot (draw the vertices as points, enumerate them, draw the primitives you want them to build...). The screen coordinates are still pixel values, but given as floats. Internally, mojo2 uses floats anyway so there's no real difference to using ints on your side.
 
Back
Top Bottom