Author Topic: opengl 3d second tryout  (Read 32727 times)

0 Members and 1 Guest are viewing this topic.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: opengl 3d second tryout
« Reply #40 on: February 19, 2009 »
It either looks like it's lit from near the back, or some of your normals are coming out 0 in length.

Jim
Challenge Trophies Won:

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: opengl 3d second tryout
« Reply #41 on: February 20, 2009 »
While taking a break for the model loading stuff, I figured out how to do render to texture using the glCopyTexSubImage2D command. I had used it before but with some 2d stuff. Its not the fastest way of doing it, but I think that using extensions might have to wait a bit :)



You can preview my very basic and simple test here: http://zac-interactive.dk/temp/r2t.zip

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: opengl 3d second tryout
« Reply #42 on: February 20, 2009 »
If you really want Render To Texture, you need to look at pbuffers (old, compatible, sometimes incredibly slow, sometimes fast), and the framebuffer extensions - new, fast, not in every driver.

Jim
Challenge Trophies Won:

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: opengl 3d second tryout
« Reply #43 on: March 10, 2009 »
I am fairly certain that my .obj model loader is working as expected, so I thought that I would post it in case someone else would be able to get something out of it.

Code: [Select]
Function loadOBJmodel:TMesh(loadfile:String)
Local tmp:TMesh = TMesh.init()

Local sline:String, ck:String
Local v1:String, v2:String, v3:String
Local f1:String, f2:String, f3:String
Local vertices:Int, texUV:Int, vNormals:Int, faces:Int

Local filein:TStream = ReadFile(loadfile)

' locate vertex data
Repeat
sline = ReadLine(filein)
ck = Left( sline,2 )

Select ck
Case "v " ' vertex
v1 = NthField( sline," ",2 )
v2 = NthField( sline," ",3 )
v3 = NthField( sline," ",4 )
tmp.addVertex(Float(v1),Float(v2),Float(v3))
vertices:+ 1
Case "vt" ' vertex texture
v1 = NthField( sline," ",2 )
v2 = NthField( sline," ",3 )
tmp.addTexUV(Float(v1),Float(v2))
Print v1+","+v2
texUV :+ 1
Case "vn" ' vertex normal
v1 = NthField( sline," ",2 )
v2 = NthField( sline," ",3 )
v3 = NthField( sline," ",4 )
tmp.addVertexNormal(Float(v1),Float(v2),Float(v3))
vNormals :+ 1
Case "f " ' face
sline = Right(sline,Len(sline)-2) ' trim start of string
sline = Replace(sline," ","/") ' replace spaces
' vertex pointers
f1 = NthField( sline,"/",1 )
f2 = NthField( sline,"/",4 )
f3 = NthField( sline,"/",7 )
tmp.addFVpointer(Int(f1)-1,Int(f2)-1,Int(f3)-1)
' texture pointers
f1 = NthField( sline,"/",2 )
f2 = NthField( sline,"/",5 )
f3 = NthField( sline,"/",8 )
tmp.addFVTexUV(Int(f1)-1,Int(f2)-1,Int(f3)-1)
' normal pointers
f1 = NthField( sline,"/",3 )
f2 = NthField( sline,"/",6 )
f3 = NthField( sline,"/",9 )
tmp.addFVnormal(Int(f1)-1,Int(f2)-1,Int(f3)-1)
faces :+ 1
End Select

Until Eof(filein)
Return tmp
End Function

' Given a String, a delimiter, And a n -- returns the nth Field
Function NthField:String(s:String, delim:String, n:Int)
Local o:Int = 1
For Local i:Int = 1 To n - 1
o = Instr(s, delim, o)
If o = 0 Then
Return ""
End If
o = o + 1
Next
Local p:Int = Instr(s, delim, o)
If p = 0 Then
Return Mid(s, o)
Else
Return Mid(s, o, p - o)
End If
End Function

Its written in BlitzMax since that the language I use, but I am certain that it wouldn't be much trouble to translate it into other languages as well.
« Last Edit: March 11, 2009 by zawran »

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: opengl 3d second tryout
« Reply #44 on: March 11, 2009 »
Looks cool but I think people would need to also see the "NthField" function which I assume is some string delimiter extracting function like we used in the old .asc to ttd lib format ? I should still have the blitzcode for those converters around somewhere, think one of them did truespace .asc models hich might be handy since I believe truespave is now free :)



Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: opengl 3d second tryout
« Reply #45 on: March 11, 2009 »
Yes I forgot that function, I will add it when I get home. Its basically just a function which finds the Nth word/number in a string, so its not overly complicated :) But for completeness sake it should have been there.

[edit] I have added the string search function that was missing.
« Last Edit: March 11, 2009 by zawran »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: opengl 3d second tryout
« Reply #46 on: March 11, 2009 »
The example reminds me of the cube in Enigma by Phenomena :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: opengl 3d second tryout
« Reply #47 on: March 12, 2009 »
Cool; The Tin Dragons making tracks! :)
I recon it would be also cool to put those converters up.
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: opengl 3d second tryout
« Reply #48 on: March 12, 2009 »
I am not sure the converter's would be much use to anyone outside me and zawran, while they just create a text file full of data statements there presented in the order needed by the ttdvectorlib, infact I am not even sure they export in the correct format for the last few versions of that to be honest. They were kinda hacked together by me to help us get more than cubes into the lib's demos and dont give anything more than vertex and face data but they mix triangle and quad face data in one file type due to how we coded our old lib. It would probably be more useful in the long run to either right proper object loaders like zawran is now, or write a converter to match your own codes vertex and face storing methods.

I will however have a look and see if I can find the truespace .asc version I think that just did triangle faces and if Istill have the code it might be useful to someone to learn from :)

[EDIT] Found the truespace .asc code whacked it up here http://www.dbfinteractive.com/forum/index.php/topic,3988.0.html for those interested.
« Last Edit: March 12, 2009 by TinDragon »

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: opengl 3d second tryout
« Reply #49 on: March 12, 2009 »
I have also made an .ASE model loader, which I will clean up and post tonight, provided I remember to do so. It is not a great file format in that it does not save a lot of information, but its easy to parse since its ascii format. But in case someone want to have a look, I will post it later on.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: opengl 3d second tryout
« Reply #50 on: March 12, 2009 »
Nice one guys, they will definately be useful.
I waseven thinking of writing a very similar utility myself for simple stuff, this would save me a job.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: opengl 3d second tryout
« Reply #51 on: March 12, 2009 »
I have posted all 3 of my current model loaders in the Bmax section. .3ds, .obj, .ase is covered. They should be fairly easy to translate into other languages being that Bmax is an easy to understand language, at least I think so :)

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: opengl 3d second tryout
« Reply #52 on: March 13, 2009 »
I was going through my mesh type and decided to add a planequad, which is basically a quad used as a plane where texture repeat is set when created. Nothing fancy or anything, but its something that could easily be used as floors/wall and other, like in a wolfenstein like maze.


Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: opengl 3d second tryout
« Reply #53 on: March 13, 2009 »
Looking good, is the plane made of multiple parts or one big quad as it looks like your texture is tiled across it rather than stretch like mine is. If its just one quad tiled then how do you do that in opengl?

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: opengl 3d second tryout
« Reply #54 on: March 13, 2009 »
Quote
If its just one quad tiled then how do you do that in opengl?

It is one quad with a tiled texture on it.

Usually for a quad with a texture you would have something like this as the texture UV coords:

0.0,0.0
1.0,0.0
1.0,1.0
0.0,1.0

If you want the texture tiled, then you simply adjust the 1.0 numbers to something else. Lets say you want the texture twice on the width, then your numbers would look like this:

0.0,0.0
2.0,0.0
2.0,1.0
0.0,1.0

So in my method which creates the quad, it takes a float for the width tiling, and a float for the height tiling, and then use these numbers instead of the 1.0 numbers.

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: opengl 3d second tryout
« Reply #55 on: March 13, 2009 »
OMG that is so simple, I thought there would be some strange command involved to set tiling and scale or something. Awesome thanks Zawran.

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: opengl 3d second tryout
« Reply #56 on: March 13, 2009 »
hehe, yeah its that simple  :D

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: opengl 3d second tryout
« Reply #57 on: March 13, 2009 »
I just finished my first version of a Heightmap from Image method. It will load an image, then create a mesh and set the height according to one of the color channels on the image. Calculating normals for the heightmap mesh takes a long time if the image is large, so I should soon write custom load/save methods for my meshes, as this would allow me to convert the meshes outside the engine, and loading the resulting binary file would be really quick.

I did not have any colormaps lying around, so the following picture is rendered using the heightmap as texture.


Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: opengl 3d second tryout
« Reply #58 on: March 14, 2009 »
Your making some very nice progress. Much faster than me at the moment, but I have been redoing my entity system to reference to a seperate mesh type after are chat about my original method making it likely to have lots of mesh overhead creating multiple entites of the same type, such as the cubes I had in my test. I have to say that from the shots and info your engine is inspiring me to work on mine.

 :bully:

cheers
Jon

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: opengl 3d second tryout
« Reply #59 on: March 14, 2009 »
I am having more fun this time around with opengl than last time I tried, and that has been a motivational factor for me. Last time I didn't really get it, but for some reason it seems more logical now. So there is a good chance that I will keep at it, which is nice, and its rewarding to see something actually work.