Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Multiple Triangles

SNIPERBBBSNIPERBBB Member Posts: 41
How can you draw two triangles, ie to make a square?
Preferred if shown in C#, C++ is okay too, won't be hard for me to convert

Comments

  • SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
    : How can you draw two triangles, ie to make a square?
    : Preferred if shown in C#, C++ is okay too, won't be hard for me to convert
    :
    Not sure how you call a D3D drawing function, but in GL it's cake.
    [code]
    glBegin(GL_TRIANGLES); //Tell GL we're starting to draw,
    //and tell it what shape

    glTexCoord2f(u.uuuuuuuu, v.vvvvvvvv); //Tell GL the U/V (S/T)
    //coordinate of the first
    //vector

    glVertex3f(x.xxxxxxxx, y.yyyyyyyy, z.zzzzzzzz); //The first vector

    glTexCoord2f(u.uuuuuuuu, v.vvvvvvvv); //Tell GL the U/V (S/T)
    //coordinate of the
    //second vector

    glVertex3f(x.xxxxxxxx, y.yyyyyyyy, z.zzzzzzzz); //The second vector

    glTexCoord2f(u.uuuuuuuu, v.vvvvvvvv); //Tell GL the U/V (S/T)
    //coordinate of the third
    //vector

    glVertex3f(x.xxxxxxxx, y.yyyyyyyy, z.zzzzzzzz); //The third vector

    glEnd(); //We're done drawing!
    [/code]
    Simple, eh? You could also use 'GL_QUADS' and supply four vectors, but then the video card would work harder by breaking stuff into triangles. You could also have put in six texture coordinates and six vertices to draw the square in a single pass, or as many as you want to! Same with quads. Maybe one of our resident D3D users can explain the DX function-call to use, or class to create to draw stuff in DX.

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

  • SNIPERBBBSNIPERBBB Member Posts: 41
    [b][red]This message was edited by SNIPERBBB at 2004-3-15 23:3:40[/red][/b][hr]
    im not working with GL unfortunatley, i got such nice DX tools to go over to GL i might if i get into more serious programming
  • gautamgautam Member Posts: 642
    [b][red]This message was edited by gautam at 2004-3-17 5:8:43[/red][/b][hr]
    Ok, lets get down to how to render two triangles - no specific API

    This is how a square is with 2 triangles

    [code]
    ______
    | |
    | |
    | |
    ------
    [/code]

    Lets says you start from bottom left and lets give it vertices 0,0. Let me call it point A. Now lets take the left of as 10, 0. Let me call it B. And now similarly top right and top left will be 0, 10 and 10, 0. Let me call it point C and D.

    So A -> 0, 0
    B -> 10, 0
    c -> 10, 10
    D -> 0, 10

    So you would essentially doing the following to draw 2 triangles to render a square

    [code]
    Begin(TRIANGLE_MODE)
    DrawVertex(A)
    DrawVertex(B)
    DrawVertex(D)

    DrawVertex(D)
    DrawVertex(B)
    DrawVertex(C)
    END TRIANGLE_MODE
    [/code]

    With OpenGL you would do

    [code]
    glBegin(GL_TRIANGLES);
    glVertex2fv(A);
    glVertex2fv(B);
    glVertex2fv(D);
    glVertex2fv(D);
    glVertex2fv(B);
    glVertex2fv(C);
    glEnd()
    [/code]

    With DirectX you would probably end up having a custom vertex structure and then you would have a variable like

    [code]
    CUSTOMVERTEX vertices[] = {
    { A },
    { B },
    { D },
    { D },
    { B },
    { C }
    }
    [/code]

    And then you would be calling CreateVertexBuffer(...) and DrawPrimitive(...)


    : [b][red]This message was edited by SNIPERBBB at 2004-3-15 23:3:40[/red][/b][hr]
    : im not working with GL unfortunatley, i got such nice DX tools to go over to GL i might if i get into more serious programming
    :



Sign In or Register to comment.