BBC BASIC
« D3D image creation and display tools. Any ideas? »

Welcome Guest. Please Login or Register.
Jan 20th, 2018, 4:20pm


Cross-platform BBC BASIC (Win32, Linux x86, Android, Mac OS-X, Raspberry Pi)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: D3D image creation and display tools. Any ideas?  (Read 382 times)
michael
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 141
question D3D image creation and display tools. Any ideas?
« Thread started on: Aug 27th, 2017, 2:39pm »

This needs to be saved in a writable directory before it is executed.

This program generates a triangle in a file and displays it all in one program. ( I merged two programs that were in the lessons and dissected the information in REMS and modified it to do what it does.

I would like to create more than 1 image, and use this version of D3D, as it has the components to create the images as well as display them.

Richard, would you have any ideas? If I can get this worked out completely, I can work on duplication and populating a world.
This program was assembled a long time ago, but I need to start getting this figured out, because it needs to be worked out.
Code:
   INSTALL @lib$+"D3DLIB"
      PROCcreate3d
      MODE 8
      DIM l%(0), b%(1), n%(1), f%(1), s%(1), m%(1), t%(1), y(1), p(1), r(1), X(1), Y(1), Z(1), e(2), a(2)
      ON CLOSE PROCcleanup:QUIT
      ON ERROR PROCcleanup:PRINT REPORT$:END
      d% = FN_initd3d(@hwnd%, 1, 0)
      IF d% = 0 ERROR 100, "Can't initialise Direct3D"
      b%(0) = FN_load3d(d%, @dir$+"TRIANGLE.B3D", n%(0), f%(0), s%(0))
      IF b%(0) = 0 ERROR 100, "Can't load TRIANGLE.B3D"
      REM  t%(0) = FN_loadtexture(d%, @dir$+"blue.BMP")
      REM IF t%(0) = 0 ERROR 100, "Can't load face.JPG"
      e() = 0, 0, -6
      a() = 0, 0, 0
      l%()=1
      REPEAT
  
        y() = 0:REM yaw (rotations around the Y axis)
        REM pitch
        p() =  0:REM TIME/100 (pitch angles rotations around the X axis)
        REM roll
        r() =  0:REM TIME/40 (roll angles (rotations around the Z axis)
        REM X (right left)
        X() =  0:REM SIN(TIME/200)
        REM Y() up and down
        Y() = 0
        REM Z() depth
        Z() =  10 :REM
        REM PROC_render(d%, &FF7F7F7F, 0, l%(), 2, m%(), t%(), b%(), n%(), f%(), s%(), y(), p(), r(), X(), Y(), Z(), e(), a(), PI/4, 5/4, 1, 1000)
        PROC_render(d%, &FF7F7F7F, 0, l%(), 2, m%(), t%(), b%(), n%(), f%(), s%(), y(), p(), r(), X(), Y(), Z(), e(), a(), PI/4, 5/4, 1, 1000) :REM experimental
        REM          1     2       3   4    5   6     7     8     9     10    11   yaw pitch roll X    Y    Z eye0123  18   19   20   ^mcd  ^( cam to farplane dist)
        REM 1 Val returned from FN_init3D
        REM 2 back color   3 #of lights   4 light pointers
        REM mcd - minimum near cam distance
  
      UNTIL INKEY(1)=0
      END
      DEF PROCcleanup
      t%(1) += 0:IF t%(1) PROC_release(t%(1))
      b%(0) += 0:IF b%(0) PROC_release(b%(0))
      b%(1) += 0:IF b%(1) PROC_release(b%(1))
      d% += 0   :IF d%    PROC_release(d%)
      ENDPROC
      DEF PROCcreate3d
      F% = OPENOUT"TRIANGLE.B3D"
      PROC4(3):REM 3 vertices
      PROC4(&100042):REM vertex size &10 and format &42
      REM       LL x            LL y            LL z
      PROC4(FN_f4(-1.0)):PROC4(FN_f4(-1.0)):PROC4(FN_f4(1.0)):PROC4(&FF0000FF)
      REM       LR x            LR y            LR z
      PROC4(FN_f4(1.0)):PROC4(FN_f4(-1.0)):PROC4(FN_f4(1.0)):PROC4(&FF00FF00)
      REM     PEAK X     PEAK Y             PEAK Z
      PROC4(FN_f4(0.0)):PROC4(FN_f4(1.0)):PROC4(FN_f4(0.0)):PROC4(&FFFF0000)
      CLOSE #F%
      ENDPROC
      DEF PROC4(A%):BPUT#F%,A%:BPUT#F%,A%>>8:BPUT#F%,A%>>16:BPUT#F%,A%>>24:ENDPROC
  
« Last Edit: Aug 27th, 2017, 7:34pm by michael » User IP Logged

I like reinventing the wheel, but for now I will work on tools for D3D
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
question Re: D3D image creation and display tools. Any idea
« Reply #1 on: Aug 27th, 2017, 6:55pm »

on Aug 27th, 2017, 2:39pm, michael wrote:
This program generates a triangle in a file and displays it all in one program.

Can I suggest that you replace D3DLIB with D3DLIBA and add the extra, final, 'camera roll' parameter to PROC_render (set it to zero)? That way it will be easier to maintain compatibility with BBCSDL and make the program truly 'cross platform'.

I've listed below a version which runs unmodified on BB4W and BBCSDL (all editions).

Quote:
Richard, would you have any ideas?

About what? You seem to have grasped the basics, what are you stuck on?

Richard.

Code:
      IF INKEY$(-256)="W" INSTALL @lib$+"D3DLIBA" ELSE INSTALL @lib$+"ogllib"
      PROCcreate3d
      MODE 8
      DIM l%(0), b%(1), n%(1), f%(1), s%(1), m%(1), t%(1), y(1), p(1), r(1), X(1), Y(1), Z(1), e(2), a(2)
      ON CLOSE PROCcleanup:QUIT
      ON ERROR PROCcleanup:PRINT REPORT$:END
      IF INKEY$(-256)="W" d% = FN_initd3d(@hwnd%, 1, 0) ELSE d% = FN_initgl(@hwnd%, 1, 0)
      IF d% = 0 ERROR 100, "Can't initialise Direct3D"
      b%(0) = FN_load3d(d%, @dir$+"TRIANGLE.B3D", n%(0), f%(0), s%(0))
      IF b%(0) = 0 ERROR 100, "Can't load TRIANGLE.B3D"
      REM  t%(0) = FN_loadtexture(d%, @dir$+"blue.BMP")
      REM IF t%(0) = 0 ERROR 100, "Can't load face.JPG"
      e() = 0, 0, -6
      a() = 0, 0, 0
      l%()=1
      REPEAT

        y() = 0:REM yaw (rotations around the Y axis)
        REM pitch
        p() =  0:REM TIME/100 (pitch angles rotations around the X axis)
        REM roll
        r() =  0:REM TIME/40 (roll angles (rotations around the Z axis)
        REM X (right left)
        X() =  0:REM SIN(TIME/200)
        REM Y() up and down
        Y() = 0
        REM Z() depth
        Z() =  10 :REM
        REM PROC_render(d%, &FF7F7F7F, 0, l%(), 2, m%(), t%(), b%(), n%(), f%(), s%(), y(), p(), r(), X(), Y(), Z(), e(), a(), PI/4, 5/4, 1, 1000)
        PROC_render(d%, &FF7F7F7F, 0, l%(), 2, m%(), t%(), b%(), n%(), f%(), s%(), y(), p(), r(), X(), Y(), Z(), e(), a(), PI/4, 5/4, 1, 1000, 0) :REM experimental
        REM          1     2       3   4    5   6     7     8     9     10    11   yaw pitch roll X    Y    Z eye0123  18   19   20   ^mcd  ^( cam to farplane dist)
        REM 1 Val returned from FN_init3D
        REM 2 back color   3 #of lights   4 light pointers
        REM mcd - minimum near cam distance

      UNTIL INKEY(1)=0
      END
      DEF PROCcleanup
      t%(1) += 0:IF t%(1) PROC_release(t%(1))
      b%(0) += 0:IF b%(0) PROC_release(b%(0))
      b%(1) += 0:IF b%(1) PROC_release(b%(1))
      d% += 0   :IF d%    PROC_release(d%)
      ENDPROC
      DEF PROCcreate3d
      F% = OPENOUT"TRIANGLE.B3D"
      PROC4(3):REM 3 vertices
      PROC4(&100042):REM vertex size &10 and format &42
      REM       LL x            LL y            LL z
      PROC4(FN_f4(-1.0)):PROC4(FN_f4(-1.0)):PROC4(FN_f4(1.0)):PROC4(&FF0000FF)
      REM       LR x            LR y            LR z
      PROC4(FN_f4(1.0)):PROC4(FN_f4(-1.0)):PROC4(FN_f4(1.0)):PROC4(&FF00FF00)
      REM     PEAK X     PEAK Y             PEAK Z
      PROC4(FN_f4(0.0)):PROC4(FN_f4(1.0)):PROC4(FN_f4(0.0)):PROC4(&FFFF0000)
      CLOSE #F%
      ENDPROC
      DEF PROC4(A%):BPUT#F%,A%:BPUT#F%,A%>>8:BPUT#F%,A%>>16:BPUT#F%,A%>>24:ENDPROC 


« Last Edit: Aug 27th, 2017, 7:53pm by Richard Russell » User IP Logged

michael
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 141
question Re: D3D image creation and display tools. Any idea
« Reply #2 on: Aug 27th, 2017, 7:37pm »

Thanks for the reply. I will look at the library you suggested and see if there is more I may have missed.
User IP Logged

I like reinventing the wheel, but for now I will work on tools for D3D
michael
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 141
question Re: D3D image creation and display tools. Any idea
« Reply #3 on: Aug 29th, 2017, 01:41am »

I constructed this square out of two triangles. I tried to add the texture to it. See anything that may help? I was hoping also to make my own colors that I could fill the pieces I make. Textures are fine, but it would be nice to know how to fill each triangle with a specific color.

I have a feeling that I needed to actually make the full square instead of the two triangles. Am I right?
Code:
      IF INKEY$(-256)="W" INSTALL @lib$+"D3DLIBA" ELSE INSTALL @lib$+"OGLLIB"
      PROCcreate3d
      MODE 8
      DIM l%(0), b%(1), n%(1), f%(1), s%(1), m%(1), t%(1), y(1), p(1), r(1), X(1), Y(1), Z(1), e(2), a(2)
      ON CLOSE PROCcleanup:QUIT
      ON ERROR PROCcleanup:PRINT REPORT$:END
      IF INKEY$(-256)="W" d% = FN_initd3d(@hwnd%, 1, 0) ELSE d% = FN_initgl(@hwnd%, 1, 0)
      IF d% = 0 ERROR 100, "Can't initialise Direct3D"
      b%(0) = FN_load3d(d%, @dir$+"TRIANGLE.B3D", n%(0), f%(0), s%(0))
      IF b%(0) = 0 ERROR 100, "Can't load TRIANGLE.B3D"
      t%(1) = FN_loadtexture(d%, @dir$+"purple.JPG")
      IF t%(1) = 0 ERROR 100, "Can't load face.JPG"
      e() = 0, 0, -6
      a() = 0, 0, 0
      l%()=1
      REPEAT
  
        y() +=.01:REM yaw (rotations around the Y axis)
        REM pitch
        p() =0:REM TIME/100 (pitch angles rotations around the X axis)
        REM roll
        r() = 0:REM TIME/40 (roll angles (rotations around the Z axis)
        REM X (right left)
        X() = 0:REM SIN(TIME/200)
        REM Y() up and down
        Y() = 0
        REM Z() depth
        Z() =  10:REM
  
        REM PROC_render(d%, &FF7F7F7F, 0, l%(), 2, m%(), t%(), b%(), n%(), f%(), s%(), y(), p(), r(), X(), Y(), Z(), e(), a(), PI/4, 5/4, 1, 1000)
        PROC_render(d%, &FF7F7F7F, 0, l%(), 2, m%(), t%(), b%(), n%(), f%(), s%(), y(), p(), r(), X(), Y(), Z(), e(), a(), PI/4, 5/4, 1, 1000, 0) :REM experimental
        REM          1     2       3   4    5   6     7     8     9     10    11   yaw pitch roll X    Y    Z eye0123  18   19   20   ^mcd  ^( cam to farplane dist)
        REM 1 Val returned from FN_init3D
        REM 2 back color   3 #of lights   4 light pointers
        REM t%() - holds texture
        REM mcd - minimum near cam distance
  
      UNTIL INKEY(1)=0
      END
      DEF PROCcleanup
      t%(1) += 0:IF t%(1) PROC_release(t%(1))
      b%(0) += 0:IF b%(0) PROC_release(b%(0))
      b%(1) += 0:IF b%(1) PROC_release(b%(1))
      d% += 0   :IF d%    PROC_release(d%)
      ENDPROC
      DEF PROCcreate3d
      F% = OPENOUT"TRIANGLE.B3D"
      PROC4(6):REM 3 vertices
      PROC4(&100042):REM vertex size &10 and format &42
      REM       LL x            LL y            LL z
      PROC4(FN_f4(-1.0)):PROC4(FN_f4(-1.0)):PROC4(FN_f4(1.0)):PROC4(&FF0000FF)
      REM       LR x            LR y            LR z
      PROC4(FN_f4(1.0)):PROC4(FN_f4(-1.0)):PROC4(FN_f4(1.0)):PROC4(&FF00FF00)
      REM     PEAK X     PEAK Y             PEAK Z
      PROC4(FN_f4(1.0)):PROC4(FN_f4(1.0)):PROC4(FN_f4(1.0)):PROC4(&FFFF0000)

      PROC4(FN_f4(-1.0)):PROC4(FN_f4(-1.0)):PROC4(FN_f4(1.0)):PROC4(&FF0000FF)
      REM       LR x            LR y            LR z
      PROC4(FN_f4(-1)):PROC4(FN_f4(1.0)):PROC4(FN_f4(1.0)):PROC4(&FF00FF00)
      REM     PEAK X     PEAK Y             PEAK Z
      PROC4(FN_f4(1.0)):PROC4(FN_f4(1.0)):PROC4(FN_f4(1.0)):PROC4(&FFFF0000)

      CLOSE #F%
      ENDPROC
      DEF PROC4(A%):BPUT#F%,A%:BPUT#F%,A%>>8:BPUT#F%,A%>>16:BPUT#F%,A%>>24:ENDPROC
 


« Last Edit: Aug 29th, 2017, 01:56am by michael » User IP Logged

I like reinventing the wheel, but for now I will work on tools for D3D
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
question Re: D3D image creation and display tools. Any idea
« Reply #4 on: Aug 29th, 2017, 11:39am »

on Aug 29th, 2017, 01:41am, michael wrote:
I constructed this square out of two triangles. I tried to add the texture to it. See anything that may help?

If you are going to use a texture, you must include the texture coordinates in the vertex description, otherwise how does the renderer know how to map the texture onto the triangle(s)? If you look at the documentation for the vertex description here you'll see that you need to include &100 (bit 16) in the vertex flags and add 8 bytes (for the texture coordinates) to the vertex descriptor.

Quote:
it would be nice to know how to fill each triangle with a specific color.

But you've already done that! The example you posted previously, and the code you listed today, both contain direct colours for the vertices:

Code:
      PROC4(FN_f4(-1.0)):PROC4(FN_f4(-1.0)):PROC4(FN_f4(1.0)):PROC4(&FF0000FF):REM <- blue
      PROC4(FN_f4(1.0)):PROC4(FN_f4(-1.0)):PROC4(FN_f4(1.0)):PROC4(&FF00FF00):REM <- green
      PROC4(FN_f4(0.0)):PROC4(FN_f4(1.0)):PROC4(FN_f4(0.0)):PROC4(&FFFF0000):REM <- red 

Setting the three vertices to the same colour will, of course, result in a uniformly-coloured triangle.

Richard.
User IP Logged

michael
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 141
question Re: D3D image creation and display tools. Any idea
« Reply #5 on: Aug 29th, 2017, 2:05pm »

Ah yes!! I worked out how to make the colors uniform. I will look at the texture part to see if I can get it figured out later today. Thanks Richard.


User IP Logged

I like reinventing the wheel, but for now I will work on tools for D3D
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
question Re: D3D image creation and display tools. Any idea
« Reply #6 on: Aug 29th, 2017, 3:01pm »

on Aug 29th, 2017, 2:05pm, michael wrote:
I will look at the texture part to see if I can get it figured out later today.

You can look at Rubik.bbc (in the BBCSDL examples/games directory) which creates textured squares, each consisting of two triangles:

Code:
      X% = OPENOUT(@tmp$ + "squarex.fvf")
      ntriangles% = 2
      BPUT #X%,ntriangles% * 3 : BPUT#X%,0 : BPUT #X%,0 : BPUT#X%,0 : REM No. of vertices
      BPUT #X%,&02 : BPUT #X%,1 : BPUT #X%,20 : BPUT#X%,0 : REM Vertex format and size

      FOR V% = 0 TO 3*ntriangles%-1
        READ x, y : v = 0.5 + x: u = 0.5 + y
        PROC4(X%,0) : PROC4(X%,x) : PROC4(X%,y) : PROC4(X%,u) : PROC4(X%,v)
      NEXT
      DATA  0.5, -0.5, -0.5, -0.5, -0.5,  0.5
      DATA -0.5,  0.5,  0.5,  0.5,  0.5, -0.5 

Incidentally whilst all but one of the Rubik cube's faces are plain-coloured, I decided to use textures to achieve it. The reason was that if you embed the colour in the vertex descriptor every different-coloured face needs a different descriptor, whereas by using textures you just need one descriptor and you can apply the different colours (i.e. textures) later.

Richard.
« Last Edit: Aug 29th, 2017, 3:02pm by Richard Russell » User IP Logged

michael
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 141
question Re: D3D image creation and display tools. Any idea
« Reply #7 on: Aug 31st, 2017, 12:54am »

Awesome Richard ! I think I have the textures figured out to a degree.

I will now work on a game pieces library, and once I am skilled at it, I will make a training video that will break down all the aspects of using D3D for beginners.

I know there are a lot of people that would like to do it and I think BBC Basic is the easiest way.

Thanks!
User IP Logged

I like reinventing the wheel, but for now I will work on tools for D3D
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
question Re: D3D image creation and display tools. Any idea
« Reply #8 on: Aug 31st, 2017, 09:00am »

on Aug 31st, 2017, 12:54am, michael wrote:
I will make a training video that will break down all the aspects of using D3D for beginners.

That sounds like a great idea, but it's not something to rush into. Can I also suggest that you steer away from referring to D3D (i.e. Direct3D, which is Windows specific) and try to keep everything platform-agnostic?

I've put a lot of effort into making the BB4W and BBCSDL 3D graphics libraries as compatible with each other as I reasonably can, and it would be irritating to see a 'training video' concentrate on one to the exclusion of the other.

Practically, the main thing to avoid is textures in formats other than BMP because that's the only one OGLLIB (and GLESLIB) can currently read.

Richard.
User IP Logged

michael
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 141
question Re: D3D image creation and display tools. Any idea
« Reply #9 on: Aug 31st, 2017, 11:46am »

I can mix scenes from each platform that I have and would refer to BBC4W and BBCSDL 3D for each example.

That way it covers all bases.

This will be of course, when I am skilled at creating the 3D scenes and animating an appealing game focus.

So it will be quite a while before a video would be made and I could of course, show the forum the video before it becomes permanent on YouTube.
User IP Logged

I like reinventing the wheel, but for now I will work on tools for D3D
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
question Re: D3D image creation and display tools. Any idea
« Reply #10 on: Sep 4th, 2017, 7:08pm »

The supplied example program pyramid.bbc (in the BBCSDL examples\graphics directory) is not as useful as it might be because it relies on existing files pyramid.fvf and base.fvf, the contents of which are not documented. In the next release of BBCSDL I intend to modify the program so that it creates these files itself (as bbcowl.bbc, lighting.bbc and world.bbc already do for their own object files).

With that change there will be code examples for creating objects with plain-coloured faces, texture-mapped faces and surface normals (for lighting).

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Donate $6.99 for 50,000 Ad-Free Pageviews!


This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls