@hwnd%

Discussions related to graphics (2D and 3D), animation and games programming
Richard Russell
Posts: 667
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Ric wrote: Sun 15 Mar 2026, 15:26 but i copied it from the original tutorials on D3D11
That demonstrates how old they are. Back then, it may be that it was the recommended way to find a pointer to a string; that hasn't been the case since PTR(strings$) was introduced several years ago, largely to support 64-bits operation!

Earlier in this very thread I wrote: "when I modified BBCSDL from 32-bits to 64-bits there were places where I replaced what are absolute addresses in the 32-bit version with relative addresses in the 64-bit version, so I could continue to use a 32-bit value. The 'pointer' in a string descriptor is an example".

So whilst it is possible (but not recommended) to extract the string pointer from the string descriptor in 32-bits BBC BASIC, it is not possible in 64-bits. It would have been an entirely understandable mistake for you to make had I not drawn attention to this specific issue only a few days ago. :oops:

Unfortunately I don't have the time or the patience to give you the degree of help you need. I have every sympathy with your difficulties in writing what is cutting-edge code that requires a deep understanding not only of BBC BASIC but also of Direct3D 11. Once upon a time there would have been others to share the load (Jon Ripley and Malcolm Marten for example) but they are long gone.

We have a situation in which you are probably one of only a handful of people still programming in BBC BASIC, and the only one doing anything non-trivial. Perhaps you should consider switching to a BASIC (or even another language) which is more popular and better supported.
Richard Russell
Posts: 667
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Richard Russell wrote: Sun 15 Mar 2026, 17:34 We have a situation in which you are probably one of only a handful of people still programming in BBC BASIC
With BBC BASIC for Windows being a paid-for product, it was possible to estimate how many users there were likely to be, based on an assumption of 'half-life', i.e. for how long it would typically be used following purchase. However since BBC BASIC for SDL 2.0 is completely free, I have no statistics to call upon to make even a rough guess (I don't know whether it would be possible to record the number of downloads, but I don't currently).

So just about the only basis on which I can judge the likely user base of BBCSDL is the number of people who ask for support here, and that is small (close to zero if Ric has now given up on BBC BASIC). But of course the small number of queries may reflect the quality of the documentation - making them unnecessary - rather than the number of users (unlikely, but one can dream). :?

I remember that some while ago David Williams attempted to estimate the total number of users, and he came up with a wide range of figures, reflecting the difficulty of the exercise (I've forgotten what the range was, but the low end was a very small number). I think that pessimistic estimate may have contributed to his decision to stop using my BASICs and concentrate on RISC OS.

My current plan is to keep my BASICs (BB4W, BBCSDL, BBCTTY) available for download and supported, to the extent that my own deterioration allows. In some ways it would be tempting to use the likely small number of users as an excuse to discontinue them, but as I don't actually know what that number is, it would be difficult to justify.
Ric
Posts: 311
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

I havent given up on BBC BASIC, I am just trying to find solutions to my D3D11 problems without asking for your help. I have managed to get the SwapChain working and a window to appear that I can change the colour of, however, I can not get the triangle to render in the next tutorial. I have put loads of PRINT statements in to try and find the answer, but rather annoyingly the program doesnt fail anywhere (with "number too big" or hRESULT% <> 0, it obviously fails in some way though) and the shader buffer sizes return as none zero. The only difference between what happens when i run the 32bit version and 64bit version (apart from the address sizes) are the buffer sizes which differ from 520(32bit) to 596(64bit), which i assume is due to the 64bit addressing. When i run the 64bit version, whilst trying to render the triangle, the background still changes colour, its just that the triangle doesnt render. In 32bit version the triangle renders.

I feel it is a sad moment that you are contemplating removing support for your BASICS, inevitably the moment will come, but i dont like to think that it is because nobody is using them.

I would like to ask for your help, but i got the impression from the last exchange that you dont want to give it. Here's hoping you'll change your mind.
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 667
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Ric wrote: Tue 17 Mar 2026, 20:39 I feel it is a sad moment that you are contemplating removing support for your BASICS, inevitably the moment will come, but i dont like to think that it is because nobody is using them.
I don't imagine that "nobody" is using them, that would be way too pessimistic, but equally it is probably over-optimistic to think that the reason for so few queries being posted here is because users never have any problems, or the documentation is so wonderful that they never need to ask for help. :?

Other language forums I visit, such as the Liberty BASIC forum, are very busy. So I inevitably conclude that the number of my users must be very small, unless somebody can present convincing evidence to the contrary. :(
I would like to ask for your help, but i got the impression from the last exchange that you dont want to give it.
I didn't mean to give that impression, what I said was that I don't always have the time or the patience to do it. Irrespective, you should always feel free to post here, because that's an invitation for others to help, not just me.

This forum has survived several periods when I wasn't a member or for other reasons couldn't post, so you shouldn't decide whether to post based on my availability, ability or willingness to answer.
Richard Russell
Posts: 667
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Ric wrote: Tue 17 Mar 2026, 20:39 the buffer sizes which differ from 520(32bit) to 596(64bit)
Have you checked that 596 is the correct buffer size when operating in 64 bits? I expect one of the better AI chatbots (e.g. Gemini) would be able to confirm that, or not, if asked.
Richard Russell wrote: Tue 17 Mar 2026, 21:30 I don't imagine that "nobody" is using them, that would be way too pessimistic
It looks as though I will have to revise that belief, and acknowledge that it may indeed be the case that there is not a single active user of BBC BASIC for SDL 2.0 anywhere - unless you count me! :( :shock:

I find that a very depressing thought, especially considering the time and effort I have dedicated to developing BBCSDL over the last ten years or more. :cry:
Ric
Posts: 311
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

I have just tried meta ai and copilot, both give the same unsatisfactory answer, that they can not give specific answers and the range for this minimal shader file should be between 200bytes and 2ish kbytes.
I have not really made any progress since i last posted. It has been quite frustrating because the program runs with out an immediate error, thus making error detection difficult. I have checked all the structures have the correct size elements and that all are aligned on an 8byte boundary, but the triangle still does not render!

I am not sure what code i can post for you to have a look at, as without the whole program nothing runs, but i know you dont like wading through other people mire.

If you count me, thats two of us who still use BBCSDL2, all my code for my home hub is written in it and long may it continue.
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 667
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Ric wrote: Fri 27 Mar 2026, 19:05 I have not really made any progress since i last posted. It has been quite frustrating because the program runs with out an immediate error, thus making error detection difficult.
So all of the Direct3D API calls you are making are returning a 'success' result, but are nevertheless failing to render successfully? That seems odd, as I would have expected one or more of the calls to report a failure.
Ric
Posts: 311
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

Success, Here is the code for D3D11 running on SDL64. Feels like a monumental moment :D

Code: Select all

    1 DIM SDL_SysWMinfo{version%, subsystem%, window%%, hdc%%, hinstance%%}
    2
    3 SYS "SDL_GetWindowWMInfo", @hwnd% , SDL_SysWMinfo{}
    4
    5 PROCD3DConstants
    6 PROCD3DEnumberations
    7 PROCD3DStructures
    8 PROCBASICVariables
    9
   10 VDU 23,22,SCREEN_WIDTH%;SCREEN_HEIGHT%;8,16,16,0
   11
   12 @% = &0000160A
   13 *HEX 64
   14 ON ERROR PRINT REPORT$,ERL : END : *REFRESH ON
   15 ON CLOSE PROCCleanD3D : QUIT
   16
   17 GUID_ID3D11Texture2D%% = FNguid("{6F15AAF2-D208-4E89-9AB4-489535D34F9C}")
   18 PRINT "GUID_ID3D11Texture2D%% ";GUID_ID3D11Texture2D%%
   19
   20 SYS "SDL_LoadObject","C:\Windows\System32\D3D11.DLL" TO D3D11%%
   21 IF D3D11%% = 0 THEN ERROR 0, "DirectX11 is not installed"
   22 SYS "SDL_LoadFunction", D3D11%%, "D3D11CreateDeviceAndSwapChain" TO D3D11CreateDeviceAndSwapChain%%
   23
   24 DIM VERTEX{pos{}=D3DXVECTOR3{},col{}=D3DXCOLOR{}}
   25
   26 PROCinitD3D
   27 PROCinitPipeline
   28 PROCinitGraphics
   29 PROCrenderFrame
   30
   31 *REFRESH ON
   32 PROCCleanD3D
   33
   34 END
   35
   36 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
   37 "********               Render the Frame                 ********
   38 REM /////////////////////////////////////////////////////////////
   39
   40 DEF PROCrenderFrame
   41
   42 stride% = DIM(VERTEX{})
   43 offset% = 0
   44
   45 SYS DevCon.VSSetShader%%, DevCon%%, pVS%%, NULL%%, 0 TO hRESULT%%
   46 PRINT "Set V Shader Result ";hRESULT%%
   47 WAIT 20
   48
   49 SYS DevCon.PSSetShader%%, DevCon%%, pPS%%, NULL%%, 0 TO hRESUL%%
   50 PRINT "Set P Shader Result ";hRESUL%%
   51 WAIT 20
   52
   53 SYS DevCon.IASetVertexBuffers%%, DevCon%%, 0, 1, ^pVBuffer%%, ^stride%, ^offset%
   54
   55 SYS DevCon.IASetPrimitiveTopology%%, DevCon%%, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST
   56
   57 R=0.00
   58 G=0.00
   59 B=0.00
   60 *REFRESH OFF
   61 REPEAT
   62
   63   BkGrdColor.r% = FNf4(R)
   64   BkGrdColor.g% = FNf4(G)
   65   BkGrdColor.b% = FNf4(B)
   66   BkGrdColor.a% = 0
   67   R+=0.0001
   68   IF R>1 THEN R=0
   69   G+=0.0003
   70   IF G>1 THEN G=0
   71   B+=0.0007
   72   IF B>1 THEN B=0
   73
   74   SYS DevCon.ClearRenderTargetView%%, DevCon%%, BackBuffer%%, BkGrdColor{}
   75   SYS DevCon.Draw%%, DevCon%%, 3, 0
   76   SYS SwapChain.Present%%, SwapChain%%, 0, 0
   77
   78 UNTIL INKEY(-99) = -1
   79
   80 ENDPROC
   81
   82 REM /////////////////////////////////////////////////////////////
   83 "********               Render the Frame                 ********
   84 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
   85
   86 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
   87 "********                Initialise D3D                  ********
   88 REM /////////////////////////////////////////////////////////////
   89
   90 DEF PROCinitD3D
   91
   92 DIM scd{} = DXGI_SWAP_CHAIN_DESC{}
   93 scd.BufferCount% = 1
   94 scd.BufferDesc.Width% = SCREEN_WIDTH%
   95 scd.BufferDesc.Height% = SCREEN_HEIGHT%
   96 scd.BufferDesc.Format% = DXGI_FORMAT_R8G8B8A8_UNORM
   97 scd.BufferDesc.RefreshRate.Numerator% = 60
   98 scd.BufferDesc.RefreshRate.Denominator% = 1
   99 scd.BufferUsage% = DXGI_USAGE_RENDER_TARGET_OUTPUT
  100 scd.OutputWindow% = SDL_SysWMinfo.window%%
  101 scd.SampleDesc.Count% = 1
  102 scd.SampleDesc.Quality% = 0
  103 scd.Windowed% = D3DTRUE
  104
  105 SYS D3D11CreateDeviceAndSwapChain%%, NULL%%, D3D_DRIVER_TYPE_HARDWARE%, NULL%%, D3D11_CREATE_DEVICE_DEBUG, NULL%%, NULL%, D3D11_SDK_VERSION%, scd{}, ^SwapChain%%, ^Dev%%, NULL%%, ^DevCon%% TO hRESULT%
  106 IF hRESULT% <> D3D_CREATED THEN ERROR 100, "CreateDeviceAndSwapChain failed: "+STR$~hRESULT%
  107
  108 ](^SwapChain{}+8) = ]SwapChain%%
  109 ](^Dev{}+8)       = ]Dev%%
  110 ](^DevCon{}+8)    = ]DevCon%%
  111 PRINT "SwapChain%%             ";SwapChain%%
  112 PRINT "Dev(ice)%%              ";Dev%%
  113 PRINT "Dev(ice)Con(text)%%     ";DevCon%%
  114 PRINT "SwapChain hRESULT%      ";hRESULT%
  115 PRINT
  116 WAIT 20
  117
  118 SYS SwapChain.GetBuffer%%, SwapChain%%, NULL%, GUID_ID3D11Texture2D%%, ^pBackBuffer%% TO hRESULT%
  119 PRINT "pBackBuffer%%           ";pBackBuffer%%
  120 PRINT "pBackBuffer%% hRESULT%  ";hRESULT%
  121 PRINT
  122 WAIT 20
  123
  124 SYS Dev.CreateRenderTargetView%%, Dev%%, pBackBuffer%%, NULL%, ^BackBuffer%% TO hRESULT%
  125 PRINT "BackBuffer%%            ";pBackBuffer%%
  126 PRINT "BackBuffer%% hRESULT%   ";hRESULT%
  127 PRINT
  128 WAIT 20
  129
  130 SYS ](]pBackBuffer%%+16), pBackBuffer%%
  131
  132 SYS DevCon.OMSetRenderTargets%%, DevCon%%, 1, ^BackBuffer%%, NULL%
  133
  134 DIM viewport{} = D3D11_VIEWPORT{}
  135
  136 viewport.Width% = FNf4(SCREEN_WIDTH%)
  137 viewport.Height% = FNf4(SCREEN_HEIGHT%)
  138 viewport.MinDepth% = 0
  139 viewport.MaxDepth% = FNf4(1.0)
  140 viewport.TopLeftX% = 0
  141 viewport.TopLeftY% = 0
  142
  143 SYS DevCon.RSSetViewports%%, DevCon%%, 1, viewport{} TO hRESULT%%
  144 PRINT "SetViewpotrs hRESULT%   ";hRESULT%
  145 PRINT
  146 WAIT 20
  147
  148 ENDPROC
  149
  150 REM /////////////////////////////////////////////////////////////
  151 "********                Initialise D3D                  ********
  152 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  153
  154 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  155 "********            Initialise the Graphics             ********
  156 REM /////////////////////////////////////////////////////////////
  157
  158 DEF PROCinitGraphics
  159
  160 DIM ourVertices{(2)} = VERTEX{}
  161
  162 ourVertices{(0)}.pos.x% = 0
  163 ourVertices{(0)}.pos.y% = FNf4(0.5)
  164 ourVertices{(0)}.pos.z% = FNf4(0.5)
  165 ourVertices{(0)}.col.r% = FNf4(1.0)
  166 ourVertices{(0)}.col.g% = FNf4(0.0)
  167 ourVertices{(0)}.col.b% = FNf4(0.0)
  168 ourVertices{(0)}.col.a% = FNf4(1.0)
  169
  170 ourVertices{(1)}.pos.x% = FNf4(0.5)
  171 ourVertices{(1)}.pos.y% = FNf4(-0.5)
  172 ourVertices{(1)}.pos.z% = FNf4(0.5)
  173 ourVertices{(1)}.col.r% = FNf4(0.0)
  174 ourVertices{(1)}.col.g% = FNf4(1.0)
  175 ourVertices{(1)}.col.b% = FNf4(0.0)
  176 ourVertices{(1)}.col.a% = FNf4(1.0)
  177
  178 ourVertices{(2)}.pos.x% = FNf4(-0.5)
  179 ourVertices{(2)}.pos.y% = FNf4(-0.5)
  180 ourVertices{(2)}.pos.z% = FNf4(0.5)
  181 ourVertices{(2)}.col.r% = FNf4(0.0)
  182 ourVertices{(2)}.col.g% = FNf4(0.0)
  183 ourVertices{(2)}.col.b% = FNf4(1.0)
  184 ourVertices{(2)}.col.a% = FNf4(1.0)
  185
  186 DIM bd{}           = D3D11_BUFFER_DESC{}
  187 bd.Usage%          = D3D11_USAGE_DYNAMIC
  188 bd.ByteWidth%      = DIM(VERTEX{}) * 3
  189 bd.BindFlags%      = D3D11_BIND_VERTEX_BUFFER
  190 bd.CPUAccessFlags% = D3D11_CPU_ACCESS_WRITE
  191
  192 SYS Dev.CreateBuffer%%, Dev%%, bd{}, NULL%%, ^pVBuffer%% TO hRESULT%
  193 PRINT "CreateBuffer%% hRESULT% ";hRESULT%
  194 PRINT
  195 WAIT 20
  196
  197 DIM ms{} = D3D11_MAPPED_SUBRESOURCE{}
  198 SYS DevCon.Map%%, DevCon%%, pVBuffer%%, NULL%, D3D11_MAP_WRITE_DISCARD, NULL%, ms{}
  199 SYS "RtlMoveMemory",ms.pData%%, ourVertices{(0)}, DIM(VERTEX{}) * 3
  200 SYS DevCon.Unmap%%, DevCon%%, pVBuffer%%, NULL%
  201
  202 ENDPROC
  203
  204 REM /////////////////////////////////////////////////////////////
  205 "********            Initialise the Graphics             ********
  206 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  207
  208 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  209 "********            Initialise the Pipeline             ********
  210 REM /////////////////////////////////////////////////////////////
  211
  212 DEF PROCinitPipeline
  213
  214 DIM VS{} = ID3D10Blob{}
  215 hRESULT% = FN_CompileShaderFromFile(@dir$+"Lesson 5 Drawing a Triangle RCE.fx", "VShader", "vs_5_0", ^VS%%)
  216 ](^VS{}+8) = ]VS%%
  217 PRINT "PS RESULT%              ";hRESULT%
  218 WAIT 20
  219
  220 DIM PS{} = ID3D10Blob{}
  221 hRESULT% = FN_CompileShaderFromFile(@dir$+"Lesson 5 Drawing a Triangle RCE.fx", "PShader", "ps_5_0", ^PS%%)
  222 ](^PS{}+8) = ]PS%%
  223 PRINT "VS RESULT%              ";hRESULT%
  224 WAIT 20
  225
  226 SYS VS.GetBufferPointer%%, VS%% TO VBufferPointer%%
  227 SYS VS.GetBufferSize%%, VS%% TO VBufferSize%%
  228 SYS Dev.CreateVertexShader%%, Dev%%, VBufferPointer%%, VBufferSize%%, NULL%%, ^pVS%% TO hRESULT%
  229 IF hRESULT% <> 0 OR pVS%% = 0 THEN SYS VS.Release%%, VS%% : ERROR 100, "Dev:Create Vertex Shader failed: "+STR$~hRESULT%
  230 PRINT "VBufferPointer%%        ";VBufferPointer%%
  231 PRINT "VBufferSize%%           ";VBufferSize%%
  232 PRINT "VS%%                    ";VS%%
  233 WAIT 20
  234
  235 SYS PS.GetBufferPointer%%, PS%% TO PBufferPointer%%
  236 SYS PS.GetBufferSize%%, PS%% TO PBufferSize%%
  237 SYS Dev.CreatePixelShader%%, Dev%%, PBufferPointer%%, PBufferSize%%, NULL%%, ^pPS%% TO hRESULT%
  238 IF hRESULT% <> 0 OR pPS%% = 0 THEN SYS PS.Release%%, PS%% : ERROR 100, "Dev::CreatePixelShader failed: "+STR$~hRESULT%
  239
  240 PRINT "PBufferPointer%%        ";PBufferPointer%%
  241 PRINT "PBufferSize%%           ";PBufferSize%%
  242 PRINT "PS%%                    ";PS%%
  243 PRINT
  244 WAIT 20
  245
  246 DIM ied{(1)} = D3D11_INPUT_ELEMENT_DESC{}
  247
  248 ied0$ = "POSITION" + CHR$(0)
  249
  250 ied{(0)}.SemanticName%%        = PTR(ied0$)
  251 ied{(0)}.SemanticIndex%        = 0
  252 ied{(0)}.Format%               = DXGI_FORMAT_R32G32B32_FLOAT
  253 ied{(0)}.InputSlot%            = 0
  254 ied{(0)}.AlignedByteOffset%    = 0
  255 ied{(0)}.InputSlotClass%       = D3D11_INPUT_PER_VERTEX_DATA
  256 ied{(0)}.InstanceDataStepRate% = 0
  257
  258 ied1$ = "COLOR" + CHR$(0)
  259
  260 ied{(1)}.SemanticName%%        = PTR(ied1$)
  261 ied{(1)}.SemanticIndex%        = 0
  262 ied{(1)}.Format%               = DXGI_FORMAT_R32G32B32A32_FLOAT
  263 ied{(1)}.InputSlot%            = 0
  264 ied{(1)}.AlignedByteOffset%    = 12
  265 ied{(1)}.InputSlotClass%       = D3D11_INPUT_PER_VERTEX_DATA
  266 ied{(1)}.InstanceDataStepRate% = 0
  267
  268 SYS Dev.CreateInputLayout%%, Dev%%, ied{(0)}, 2, VBufferPointer%%, VBufferSize%%, ^pLayout%% TO hRESULT%
  269 IF hRESULT% <> 0 OR pLayout%% = 0 ERROR 100, "Dev:Create Input Layout failed: "+STR$~hRESULT%
  270 PRINT "pLayout%%               ";pLayout%%
  271 PRINT "pLayout hRESULT%        ";hRESULT%
  272 PRINT
  273 WAIT 20
  274
  275 SYS DevCon.IASetInputLayout%%, DevCon%%, pLayout%% TO hRESULT%%
  276 PRINT "SetInputLayout hRESULT% ";hRESULT%%
  277 PRINT
  278 WAIT 20
  279
  280 ENDPROC
  281
  282 REM /////////////////////////////////////////////////////////////
  283 "********            Initialise the Pipeline             ********
  284 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  285
  286 DEF FNf4(a#)LOCALp%%:p%%=^a#:IFABSa#<1E-38THEN=FALSE
  287 =p%%!4ANDNOT&7FFFFFFFOR(p%%!4-&38000000<<3OR!p%%>>29AND7)+(!p%%>>28AND1)
  288
  289 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  290 "********                 Clean Up D3D                   ********
  291 REM /////////////////////////////////////////////////////////////
  292
  293 DEF PROCCleanD3D
  294
  295 SwapChain%% += 0         : IF SwapChain%%         SYS SwapChain.Release%%, SwapChain%%
  296 DevCon%% += 0            : IF DevCon%%            SYS DevCon.Release%%, DevCon%%
  297 Dev%% += 0               : IF Dev%%               SYS Dev.Release%%, Dev%%
  298 BackBuffer%% += 0        : IF BackBuffer%%        SYS ](]BackBuffer%%+16), BackBuffer%%
  299 PS%% += 0                : IF PS%%                SYS PS.Release%%, PS%%
  300 VS%% += 0                : IF VS%%                SYS VS.Release%%, VS%%
  301 pPS%% += 0               : IF pPS%%               SYS ](]pPS%%+16), pPS%%
  302 pVS%% += 0               : IF pVS%%               SYS ](]pVS%%+16), pVS%%
  303 pVBuffer%% += 0          : IF pVBuffer%%          SYS ](]pVBuffer%%+16), pVBuffer%%
  304 pLayout%% += 0           : IF pLayout%%           SYS ](]pLayout%%+16), pLayout%%
  305
  306 ENDPROC
  307
  308 REM /////////////////////////////////////////////////////////////
  309 "********                 Clean Up D3D                   ********
  310 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  311
  312 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  313 "********          Load the Shaders from file            ********
  314 REM /////////////////////////////////////////////////////////////
  315 hRESULT% = FN_CompileShaderFromFile(@dir$+"Lesson 5 Drawing a Triangle RCE.fx", "VShader", "vs_5_0", ^VS%%)
  316
  317 DEF FN_CompileShaderFromFile(fileName$,shaderName$,version$,shaderAddress%%)
  318 DIM shaderBuffer%% LOCAL 2*LENfileName$+1
  319
  320 SYS "SDL_LoadObject","C:\Windows\System32\D3DCompiler_47.dll" TO compileFromFile%%
  321 PRINT "compileFromFile%%   ";compileFromFile%%
  322 IF compileFromFile%%=0 THEN
  323   *REFRESH ON
  324   ERROR 0,"D3DCompiler_47.DLL is not installed"
  325 ENDIF
  326 SYS "SDL_LoadFunction",compileFromFile%%,"D3DCompileFromFile" TO compileFromFile%%
  327 PRINT "compileFromFile%%   ";compileFromFile%%
  328 WAIT 20
  329
  330 PRINT
  331 PRINT "fileName$            ";fileName$
  332 PRINT "shaderName$          ";shaderName$
  333 PRINT "version$             ";version$
  334 PRINT "shaderAddress%%      ";shaderAddress%%
  335 WAIT 20
  336
  337 SYS "MultiByteToWideChar",0,0,fileName$,-1,shaderBuffer%%,LENfileName$+1
  338
  339 PRINT "shaderBuffer%%       ";shaderBuffer%%
  340 WAIT 20
  341
  342 SYS compileFromFile%%,shaderBuffer%%,NULL%%,NULL%%,shaderName$,version$,NULL%%,NULL%%,shaderAddress%%,^errorMessages%% TO shaderStartAddress%%
  343
  344 PRINT "shaderStartAddress%% ";shaderStartAddress%%
  345 PRINT "shaderAddress%%      ";shaderAddress%%
  346 PRINT
  347 WAIT 20
  348
  349 IF errorMessages%% THEN
  350   SYS ](]errorMessages%%+24),errorMessages%% TO showMessage%
  351   SYS "SDL_MessageBox",SDL_SysWMinfo.window%%,showMessage%,"D3DCompileFromFile",0
  352   SYS ](]errorMessages%%+16),errorMessages%%
  353 ENDIF
  354
  355 = shaderStartAddress%%
  356
  357 REM /////////////////////////////////////////////////////////////
  358 "********          Load the Shaders from file            ********
  359 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  360
  361 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  362 REM ***              Get GUID Handle                ***
  363 REM ///////////////////////////////////////////////////
  364
  365 DEF FNguid(strCLSID$)
  366
  367 lenCLSID% = 2 * LEN(strCLSID$) + 1
  368
  369 DIM pCLSID%% 30
  370 DIM psCLSID%% lenCLSID%
  371
  372 pCLSID%% = (pCLSID%%+15) AND -16
  373
  374 SYS "SDL_LoadObject","C:\Windows\System32\OLE32.DLL" TO OLE32DLL%%
  375 SYS "SDL_LoadFunction", OLE32DLL%%, "CLSIDFromString" TO CLSIDFromString%%
  376
  377 SYS "MultiByteToWideChar", 0, 0, strCLSID$, -1, psCLSID%%, lenCLSID%
  378 SYS CLSIDFromString%%, psCLSID%%, pCLSID%%
  379
  380 = pCLSID%%
  381
  382 REM ///////////////////////////////////////////////////
  383 REM ***              Get GUID Handle                ***
  384 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  385
  386
  387
  388
  389 "REM\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  390 "REM***        Definitions and Constants            ***
  391 "REM///////////////////////////////////////////////////
  392
  393 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  394 REM ***              BASICVariables                 ***
  395 REM ///////////////////////////////////////////////////
  396
  397 DEF PROCBASICVariables
  398
  399 DIM BkGrdColor{r%,g%,b%,a%}
  400
  401 SCREEN_HEIGHT%                                               = 600
  402 SCREEN_WIDTH%                                                = 960
  403
  404 ENDPROC
  405
  406 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  407 REM ***              BASICVariables                 ***
  408 REM ///////////////////////////////////////////////////
  409
  410 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  411 REM ***               D3D Constants                 ***
  412 REM ///////////////////////////////////////////////////
  413
  414 DEF PROCD3DConstants
  415
  416 D3D_CREATED                              = 0
  417 D3DTRUE                                  = 1
  418 NULL%                                    = 0
  419 NULL%%                                   = 0
  420
  421 D3D_DRIVER_TYPE_HARDWARE%                = 1
  422 DXGI_USAGE_RENDER_TARGET_OUTPUT          = 1 << (1 + 4)
  423 D3D11_SDK_VERSION%                       = 7
  424
  425 ENDPROC
  426
  427 REM ///////////////////////////////////////////////////
  428 REM ***               D3D Constants                 ***
  429 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  430
  431 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  432 REM ***              D3D Enumerations               ***
  433 REM ///////////////////////////////////////////////////
  434
  435 DEF PROCD3DEnumberations
  436
  437 D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST    = 4
  438 DXGI_FORMAT_R32G32B32A32_FLOAT           = 2
  439 DXGI_FORMAT_R32G32B32_FLOAT              = 6
  440 DXGI_FORMAT_R8G8B8A8_UNORM               = 28
  441 D3D11_INPUT_PER_VERTEX_DATA              = 0
  442 D3D11_USAGE_DYNAMIC                      = 2
  443 D3D11_BIND_VERTEX_BUFFER                 = &1
  444 D3D11_CPU_ACCESS_WRITE                   = &10000
  445 D3D11_MAP_WRITE_DISCARD                  = 4
  446 D3D11_CREATE_DEVICE_DEBUG                = &2
  447
  448 ENDPROC
  449
  450 REM ///////////////////////////////////////////////////
  451 REM ***              D3D Enumerations               ***
  452 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  453
  454 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  455 REM ***               D3D Structures                ***
  456 REM ///////////////////////////////////////////////////
  457
  458 DEF PROCD3DStructures
  459
  460 DIM D3DXCOLOR{r%,g%,b%,a%}
  461 DIM D3DXVECTOR3{x%,y%,z%}
  462
  463 DIM DXGI_RATIONAL{Numerator%,Denominator%}
  464
  465 DIM DXGI_MODE_DESC{Width%,Height%,RefreshRate{}=DXGI_RATIONAL{}, \
  466 \ Format%,ScanlineOrdering%,Scaling%}
  467
  468 DIM DXGI_SAMPLE_DESC{Count%,Quality%}
  469
  470 DIM DXGI_SWAP_CHAIN_DESC{BufferDesc{}=DXGI_MODE_DESC{}, \
  471 \ SampleDesc{}=DXGI_SAMPLE_DESC{},BufferUsage%,BufferCount%, \
  472 \ Padding%,OutputWindow%%,Windowed%,SwapEffect%,Flags%}
  473
  474 DIM D3D11_INPUT_ELEMENT_DESC{SemanticName%%,SemanticIndex%,Format%, \
  475 \ InputSlot%,AlignedByteOffset%,InputSlotClass%,InstanceDataStepRate%}
  476
  477 DIM D3D11_VIEWPORT{TopLeftX%,TopLeftY%,Width%,Height%,MinDepth%, \
  478 \ MaxDepth%}
  479
  480 DIM D3D11_MAPPED_SUBRESOURCE{pData%%,RowPitch%,DepthPitch%}
  481
  482 DIM D3D11_BUFFER_DESC{ByteWidth%,Usage%,BindFlags%,CPUAccessFlags%, \
  483 \ MiscFlags%,StructureByteStride%}
  484
  485 REM Interfaces:
  486
  487 DIM ID3D10Blob{QueryInterface%%,AddRef%%,Release%%,GetBufferPointer%%, \
  488 \ GetBufferSize%%}
  489
  490 DIM SwapChain{QueryInterface%%,AddRef%%,Release%%,SetPrivateData%%, \
  491 \ SetPrivateDataInterface%%,GetPrivateData%%,GetParent%%,GetDevice%%, \
  492 \ Present%%,GetBuffer%%,SetFullscreenState%%,GetFullscreenState%%, \
  493 \ GetDesc%%,ResizeBuffers%%,ResizeTarget%%,GetContainingOutput%%, \
  494 \ GetFrameStatistics%%,GetLastPresentCount%%}
  495
  496 REM TEXTURE IS HERE
  497
  498 DIM ID3D11Texture2D{QueryInterface%%,AddRef%%,Release%%,GetDevice%%, \
  499 \ GetPrivateData%%,SetPrivateData%%,SetPrivateDataInterface%%,GetType%%, \
  500 \ SetEvictionPriority%%,GetEvictionPriority%%,GetDesc%%}
  501
  502 DIM ID3D11ShaderResourceView{QueryInterface%%,AddRef%%,Release%%, \
  503 \ GetDevice%%,GetPrivateData%%,SetPrivateData%%,SetPrivateDataInterface%%, \
  504 \ GetResource%%,GetDesc%%}
  505
  506 DIM ID3D11RenderTargetView{QueryInterface%%,AddRef%%,Release%%, \
  507 \ GetDevice%%,GetPrivateData%%,SetPrivateData%%,SetPrivateDataInterface%%, \
  508 \ GetResource%%,GetDesc%%}
  509
  510 DIM ID3D11DepthStencilView{QueryInterface%%,AddRef%%,Release%%, \
  511 \ GetDevice%%,GetPrivateData%%,SetPrivateData%%,SetPrivateDataInterface%%, \
  512 \ GetResource%%,GetDesc%%}
  513
  514 DIM DevCon{QueryInterface%%,AddRef%%,Release%%,GetDevice%%, \
  515 \ GetPrivateData%%,SetPrivateData%%,SetPrivateDataInterface%%, \
  516 \ VSSetConstantBuffers%%,PSSetShaderResources%%,PSSetShader%%, \
  517 \ PSSetSamplers%%,VSSetShader%%,DrawIndexed%%,Draw%%,Map%%,Unmap%%, \
  518 \ PSSetConstantBuffers%%,IASetInputLayout%%,IASetVertexBuffers%%, \
  519 \ IASetIndexBuffer%%,DrawIndexedInstanced%%,DrawInstanced%%, \
  520 \ GSSetConstantBuffers%%,GSSetShader%%,IASetPrimitiveTopology%%, \
  521 \ VSSetShaderResources%%,VSSetSamplers%%,Begin%%,End%%,GetData%%, \
  522 \ SetPredication%%,GSSetShaderResources%%,GSSetSamplers%%, \
  523 \ OMSetRenderTargets%%,OMSetRenderTargetsAndUnorderedAccessViews%%, \
  524 \ OMSetBlendState%%,OMSetDepthStencilState%%,SOSetTargets%%,DrawAuto%%, \
  525 \ DrawIndexedInstancedIndirect%%,DrawInstancedIndirect%%,Dispatch%%, \
  526 \ DispatchIndirect%%,RSSetState%%,RSSetViewports%%,RSSetScissorRects%%, \
  527 \ CopySubresourceRegion%%,CopyResource%%,UpdateSubresource%%, \
  528 \ CopyStructureCount%%,ClearRenderTargetView%%, \
  529 \ ClearUnorderedAccessViewUint%%,ClearUnorderedAccessViewFloat%%, \
  530 \ ClearDepthStencilView%%,GenerateMips%%,SetResourceMinLOD%%, \
  531 \ GetResourceMinLOD%%,ResolveSubresource%%,ExecuteCommandList%%, \
  532 \ HSSetShaderResources%%,HSSetShader%%,HSSetSamplers%%, \
  533 \ HSSetConstantBuffers%%,DSSetShaderResources%%,DSSetShader%%, \
  534 \ DSSetSamplers%%,DSSetConstantBuffers%%,CSSetShaderResources%%, \
  535 \ CSSetUnorderedAccessViews%%,CSSetShader%%,CSSetSamplers%%, \
  536 \ CSSetConstantBuffers%%,VSGetConstantBuffers%%,PSGetShaderResources%%, \
  537 \ PSGetShader%%,PSGetSamplers%%,VSGetShader%%,PSGetConstantBuffers%%, \
  538 \ IAGetInputLayout%%,IAGetVertexBuffers%%,IAGetIndexBuffer%%, \
  539 \ GSGetConstantBuffers%%,GSGetShader%%,IAGetPrimitiveTopology%%, \
  540 \ VSGetShaderResources%%,VSGetSamplers%%,GetPredication%%, \
  541 \ GSGetShaderResources%%,GSGetSamplers%%,OMGetRenderTargets%%, \
  542 \ OMGetRenderTargetsAndUnorderedAccessViews%%,OMGetBlendState%%, \
  543 \ OMGetDepthStencilState%%,SOGetTargets%%,RSGetState%%,RSGetViewports%%, \
  544 \ RSGetScissorRects%%,HSGetShaderResources%%,HSGetShader%%, \
  545 \ HSGetSamplers%%,HSGetConstantBuffers%%,DSGetShaderResources%%, \
  546 \ DSGetShader%%,DSGetSamplers%%,DSGetConstantBuffers%%, \
  547 \ CSGetShaderResources%%,CSGetUnorderedAccessViews%%,CSGetShader%%, \
  548 \ CSGetSamplers%%,CSGetConstantBuffers%%,ClearState%%,Flush%%,GetType%%, \
  549 \ GetContextFlags%%,FinishCommandList%%}
  550
  551 DIM Dev{QueryInterface%%,AddRef%%,Release%%,CreateBuffer%%, \
  552 \ CreateTexture1D%%,CreateTexture2D%%,CreateTexture3D%%, \
  553 \ CreateShaderResourceView%%,CreateUnorderedAccessView%%, \
  554 \ CreateRenderTargetView%%,CreateDepthStencilView%%,CreateInputLayout%%, \
  555 \ CreateVertexShader%%,CreateGeometryShader%%, \
  556 \ CreateGeometryShaderWithStreamOutput%%,CreatePixelShader%%, \
  557 \ CreateHullShader%%,CreateDomainShader%%,CreateComputeShader%%, \
  558 \ CreateClassLinkage%%,CreateBlendState%%,CreateDepthStencilState%%, \
  559 \ CreateRasterizerState%%,CreateSamplerState%%,CreateQuery%%, \
  560 \ CreatePredicate%%,CreateCounter%%,CreateDeferredContext%%, \
  561 \ OpenSharedResource%%,CheckFormatSupport%%, \
  562 \ CheckMultisampleQualityLevels%%,CheckCounterInfo%%,CheckCounter%%, \
  563 \ CheckFeatureSupport%%,GetPrivateData%%,SetPrivateData%%, \
  564 \ SetPrivateDataInterface%%,GetFeatureLevel%%,GetCreationFlags%%, \
  565 \ GetDeviceRemovedReason%%,GetImmediateContext%%,SetExceptionMode%%, \
  566 \ GetExceptionMode%%}
  567
  568 ENDPROC
  569
  570 REM ///////////////////////////////////////////////////
  571 REM ***               D3D Structures                ***
  572 REM \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  573
  574 "REM///////////////////////////////////////////////////
  575 "REM***        Definitions and Constants            ***
  576 "REM\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
and the shader file(needs to be saved as a .fx file and placed in the same directory as the code above.

Code: Select all

struct VOut
{
    float4 position : SV_POSITION;
    float4 color : COLOR;
};

VOut VShader
(
    float4 position : POSITION, 
    float4 color : COLOR
)

{
    VOut output;

    output.position = position;
    output.color = color;

    return output;
}


float4 PShader(float4 position : SV_POSITION, float4 color : COLOR) : SV_TARGET
{
    return color;
}

Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Ric
Posts: 311
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

I am disapointed to find that *FLOAT32 only works on console versions and not BBCSDL64, so this leads to the question, is there a way of converting a whole array to float4 similar to array4() = FN_f4(array8()) without converting each element seperately?
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 667
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Ric wrote: Tue 07 Apr 2026, 21:14 I am disapointed to find that *FLOAT32 only works on console versions and not BBCSDL64
It works here:

float32.png
You do not have the required permissions to view the files attached to this post.