Author Topic: OGL Commands To Blitz3D  (Read 6431 times)

0 Members and 1 Guest are viewing this topic.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
OGL Commands To Blitz3D
« on: February 23, 2009 »
Here's whats racking my brains at present,

• Im using Blitz3D to familiarize myself and experiment with mesh making as you'd probably gathered from my recent questions.

• I have found a routine in C which uses Open GL to deal with the model.
• I have the vertex and Texture co-ordinates allready worked out and stored in arrays, the x,y,z's are in one called: Verts( Total* 3 ), and U and V's in: TexCords( Total*2 )

• How this is rendered in C/OGL, is by using:

Code: [Select]
{
mPrimitiveType = GL_TRIANGLE_STRIP;

glDrawElements(mPrimitiveType,mIndices, UInteger, mIndex);
}


What I am stuck on and want desperatly to suss out with your guys aid, is how to convert this into Blitz3D, using triangle strips.

• In Blitz3D you'd use the following commands in my mock example to create models with:
Code: [Select]

V0=Add_Vertex( XValue, YValue, ZValue, UValue, VValue )
V1=Add_Vertex( like above )
V2=Add_Vertex( etc )

Add_Triangle( Mesh, V0, V1, V2 )



Id be eternally greatfull to get this working,

Thankyou so much,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: OGL Commands To Blitz3D
« Reply #1 on: February 23, 2009 »
how to convert this into Blitz3D, using triangle strips.
If your vertices are already given in striped order, you can just draw the thing:
Code: [Select]
glBegin(GL_TRIANGLE_STRIP)
for i = 0 to numVertices
  glTexCoord2d(TexCords[i].u, TexCords[i].v)
  glVertex3f(Vertes[i].x, Verts[i].y, Verts[i].z)
next
glEnd()
To create strips you can use nvidias tristrip-tool.
Nowadays indexed triangle-lists are often faster than strips as they take better advantage of bigger caches.
« Last Edit: February 23, 2009 by hellfire »
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: OGL Commands To Blitz3D
« Reply #2 on: February 23, 2009 »
Thanks Hellfire :)

How would that be in Blitz3D like the example I posted with V0=Vertex( x,y,z,u,v ) etc?
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: OGL Commands To Blitz3D
« Reply #3 on: February 23, 2009 »
If the vertices form a strip, and are numbered 0,1,2,3,4,5,6... then your triangles are made of vertices:
0,1,2
1,2,3
2,3,4
3,4,5
...

Jim
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: OGL Commands To Blitz3D
« Reply #4 on: February 23, 2009 »
Thanks both, and to be honest I am a bit confused here.

First off, i am not using OGL, but Blitz3D commands.

And all I know is that the vertex positions for x,y,z are made up in a few loops. And they are then displayed by a triangle strip.

I dont know if they form a strip - a strip to me would be a long plane,
All I do know is they are rendered in Open GL as one; I think OGL does a few things for you, than Blitz would do.

0,1,2
etc

I wouldnt know how that made an Add_Triangle(s)

Many thanks,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: OGL Commands To Blitz3D
« Reply #5 on: February 23, 2009 »
Code: [Select]
; 0,1,2
v0 = Add_Vertex(v[0].x, v[0].y, v[0].z, uv[0].u, uv[0].v)
v1 = Add_Vertex(v[1].x, v[1].y, v[1].z, uv[1].u, uv[1].v)
v2 = Add_Vertex(v[2].x, v[2].y, v[2].z, uv[2].u, uv[2].v)
Add_Triangle(v0,v1,v2)

; 1,2,3
v0 = Add_Vertex(v[1].x, v[1].y, v[1].z, uv[1].u, uv[1].v)
v1 = Add_Vertex(v[2].x, v[2].y, v[2].z, uv[2].u, uv[2].v)
v2 = Add_Vertex(v[3].x, v[3].y, v[3].z, uv[3].u, uv[3].v)
Add_Triangle(v0,v1,v2)
etc.

A strip of triangles looks like a Rubic's Snake.
http://images.google.com.au/images?hl=en&q=triangle%20strip&um=1&ie=UTF-8&sa=N&tab=wi

Hellfire and I are just guessing it's a strip, because that's what the OpenGL code shows, but you haven't posted nearly enough of the original code for us to be able to tell.

Jim
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: OGL Commands To Blitz3D
« Reply #6 on: February 23, 2009 »
Internally Blitz handles meshes as a collection of indexed triangles; there's no support for strips.
You can put your striped meshes back into indexed triangles, but then they're not strips anymore.
If you really require strips you have to paint them manually. I don't see a reason for that, though.
What are you trying to do?
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: OGL Commands To Blitz3D
« Reply #7 on: February 23, 2009 »
here is a bit of code, it wont run properly as I quickly did a new version of it; but it gives the general idea.

What I think is meant to be happening is rather than triangle strips, rectangular quads / tubes - id opt for the later, are being made. Im not 100% as I dont know what a triangle strip is to be fair.

Thing is I dont want to give too much away, as if it works, it will feature in a release i am planning for BreakPoint. It probably wont get too much applause, but it's my first entry in a major recognized party.

Code: [Select]
Function CreateModel()       
 
Local Facets=256
Local Steps=16
Local Thickness=2   

    Local Mesh=CreateMesh()
Local Surf=CreateSurface( Mesh )

   
    Local i,j
   
   
    Local posx#, posy#, posz#
    Local posx2#, posy2#
   
   
    Local Vertex#    ( ( ( Steps + 1 ) * ( Facets + 1) +1 )*3 )
    Local texcoord#  ( ( ( Steps + 1 ) * ( Facets + 1) +1 )*2 )


    For i = 0 To Steps
           
     
        For j = 0 To Facets-1
       
            PosX=Sin(j) * Thickness
            PosY=Cos(j  / Facets) * Thickness

PosX2=Cos(i+j*thickness)
PosY2=Sin(j) * Thickness

            vertex(i * ( Facets + 1) * 3 + j * 3 + 0 ) = posx * posy + posx2 * posy2
            vertex(i * ( Facets + 1) * 3 + j * 3 + 1 ) = posx * posy + posx2 * posy2
            vertex(i * ( Facets + 1) * 3 + j * 3 + 2 ) = posx * posy + posx2 * posy2
           

            texcoord(i * ( Facets + 1) * 2 + j * 2 + 0) = ( j / Facets)
            texcoord(i * ( Facets + 1) * 2 + j * 2 + 1) = ( i / Steps) 
           
           
        Next
       
        ; create duplicate vertex For sideways wrapping
        ; otherwise identical To First vertex in the 'ring' except For the U coordinate
       
        vertex(i * (Facets + 1) * 3 + Facets * 3 + 0) = vtx(i * (Facets + 1) * 3 + 0)
        vertex(i * (Facets + 1) * 3 + Facets * 3 + 1) = vtx(i * (Facets + 1) * 3 + 1)
        vertex(i * (Facets + 1) * 3 + Facets * 3 + 2) = vtx(i * (Facets + 1) * 3 + 2)

        texcoord(i * (Facets + 1) * 2 + Facets * 2 + 0) = UScale
        texcoord(i * (Facets + 1) * 2 + Facets * 2 + 1) = texcoord(i * (Facets + 1) * 2 + 1)

    Next

    ; create duplicate ring of vertices For longways wrapping
    ; otherwise identical To First 'ring' except For the V coordinate
    For j = 0 To Facets-1
   
        vertex(Steps * (Facets + 1) * 3 + j * 3 + 0) = vertex(j * 3 + 0)
        vertex(Steps * (Facets + 1) * 3 + j * 3 + 1) = vertex(j * 3 + 1)
        vertex(Steps * (Facets + 1) * 3 + j * 3 + 2) = vertex(j * 3 + 2)

        texcoord(Steps * (Facets + 1) * 2 + j * 2 + 0) = texcoord(j * 2 + 0)
        texcoord(Steps * (Facets + 1) * 2 + j * 2 + 1) = VScale
   
    Next

    ;
    ; finally, there's one vertex that needs To be duplicated due To both U And V coordinate.
    ;
    vertex(Steps * (Facets + 1) * 3 + Facets * 3 + 0) = vertex(0)
    vertex(Steps * (Facets + 1) * 3 + Facets * 3 + 1) = vertex(1)
    vertex(Steps * (Facets + 1) * 3 + Facets * 3 + 2) = vertex(2)

    texcoord(Steps * (Facets + 1) * 2 + Facets * 2 + 0) = UScale
    texcoord(Steps * (Facets + 1) * 2 + Facets * 2 + 1) = VScale

    UpdateNormals( Mesh )
   
    Return Mesh 

End Function

I could probably make the V(0 To 3)=Vertex( blahx,blahy,blahz, blahu, blahv ) Add_Triangles inside these loops, instead of making new ones else where.

Biggest of thanks,
Clyde.
« Last Edit: February 23, 2009 by Clyde »
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: OGL Commands To Blitz3D
« Reply #8 on: February 23, 2009 »
blitz3d doesnt really do mesh creation from triangle strips like direct3d or opengl, you can create code to produce the same sort of effect yourself but it really depends what your trying to achieve. mesh's in blitz are made from 1 or more surfaces and each surface holds the information on the verts, uv's and triangles.

So the basics of making a mesh and adding triangles is like this
Code: [Select]
mesh = CreateMesh() ; Create an empty mesh
surf = CreateSurface(mesh) ; create a surface to add our triangles to

v0 = AddVertex (surf, 0,0,0, 0 ,0) ; add the vertex x,y,z,u,v
v1 = AddVertex (surf, 5,0,0, 1 ,0) ; 3 points are needed
v2 = AddVertex (surf, 5, 5,0, 1,1) ; to make a triangle, which we all know :)

tri = AddTriangle (surf,v0,v1,v2) ; then add the triangle to the surface.

you could of course add a second triangle that used 2 of the exsisting vertex and 1 new one to make a quad.
so v3 = AddVertex (surf, 0, 5,0, 0,1) and tri1 = AddTriangle (surf,v0,v2,v3)

So loading in a model to create the mesh your self you need to supply the vertex positions with u,v info and then the 3 vertex that make a triangle to the addtriangle function. Assuming the model info you are loading has given this and you have it stored somewhere it should just be a case of repeatedly adding each vertex with the AddVertex command, then do the list of face/triangle building afterwards. Most 3d model formats should tell you how many vertex are in the model and how many triangles (sometimes called faces) so 2 for next loops could be made to build the mesh.

Once you have made your mesh, then it becomes like any other model in b3d and can be moved, rotated, scaled using the same commands you use on any entity.

When building your own mesh's in code it becomes slightly more complex, you have to work out the vertex positions and uv coords yourself, simple shapes like a flat quad or even a cube are easy but more complex shapes like cylinders,sphere's etc require more work but if your using b3d itself it has ofc built in commands for those shapes, but if you want to make your own create functions for those kinds of shapes there are examples in the blitzbasic code archives, http://www.blitzbasic.com/codearcs/codearcs.php?code=1133 for example makes a torus, a demo coding favourite :)
« Last Edit: February 23, 2009 by TinDragon »

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: OGL Commands To Blitz3D
« Reply #9 on: February 23, 2009 »
Thank you very much dude.

With what you have given me as a guide, what would go into the value slots to make a triangle / quad with the info I have in the loops please dude? Anyone else now too! :D

Probably need to build it, in a seperate loop for joining up the points, and adding triangles.

Cheers and big thanks,
Clyde.
« Last Edit: February 23, 2009 by Clyde »
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: OGL Commands To Blitz3D
« Reply #10 on: February 23, 2009 »
Being secretive about it isn't going to help you at all.  If it's so important, work on something which shows the same problem here and you can apply it to your competition code later.

If you followed my link, it would show you what a triangle strip is.  The code you just posted won't be using strips though.

Each of those For loops in your new code produces an XYZUV value, so that corresponds to your Add_Vertex calls.  What's missing is the triangles - what have you tried so far?

Jim
 
Challenge Trophies Won:

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: OGL Commands To Blitz3D
« Reply #11 on: February 23, 2009 »
Quote
what would go into the value slots to make a triangle

Instead of storing the vertex and uv data in arrays, you should be feeding them to the addTriangle() function, which takes x,y,z coordinates and u,v map coordinates and creates a triangle on the surface of the mesh.

Have you done any mesh creation before that works? Something like a basic quad created from two triangles?

You might want to start with something really simple, at least until you understand all aspects of that is needed to create meshes in code. Once you successfully create a quad, then try and create a plane made up of a number of quads left to right with the texture spread across all the triangles. Then move on to having a number of quads going from top to bottom as well.

When you have some code working for that, then more complex shapes is next on the list. Perhaps creating a function to create a cube in code instead of using the built-in function could be next.

I have no idea about just how much of this 3D stuff you got down already, which is why I am suggesting the above.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: OGL Commands To Blitz3D
« Reply #12 on: February 24, 2009 »
Guys, a big thanks for your time & help and I really appreciate it all - Honestly.

Zawran, I have done quite a few things with Blitz3D; just this one kind of stumped me as it's from a dialect I am unfamiliar with that was all.

Will have to ponder over this somemore.

Cheers and hugest of thanks for your patience,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won: