Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / "Hacking" the DGDK device - Help needed

Author
Message
hayer_p
16
Years of Service
User Offline
Joined: 24th Sep 2008
Location: Norway, Trondheim
Posted: 24th Sep 2008 10:55
Hi! :- )
First I want to say something about the subject:
Hacking may not be the right word for this, but the word "hacking" get s lots of attention, and some may call this hacking...

My problem is :
I want an createVertex command in DGDK with welded vertices(Please dont flame me and tell me to use memblocks ._.)

So first of all, how would I go about accessing(writing,reading,etc) data to the DGDK DX device?

2nd, if nr. 1 is do-able : What data would I feed it with?



Off-topic: Anyone know if NuclearGlory has an "PickObject", etc command?

WTF is this textarea used for? <.< Signature? WTF is that?
Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 25th Sep 2008 13:24
I believe you can get a pointer directly to the Direct3D display device(and also the input device, sound device etc) through GDK commands(undocumented ones) have a look through the header files that come with GDK... specifically globstruct.h and DarkSDKCore.h and a couple of others ( i think most of the GDK headers have various "alternative" and in some cases "deprecated" functions and undocumented extra, working functions--usually related to internal workings that we can take advantage of

Although plugging into directX directly is a little more complex than just gettin a pointer, i think the way GDK and directX work with their respective data is a little different... what i mean is that if you change something that GDK depends on from inside directX, GDK may have no way of knowing that it has been changed.... and subsequentaly crash on ya.... it might not, but thats the risk..(you could just use alot of checking and double checking and careful programming to avoid that kind of thing though)

If it ain't broke.... DONT FIX IT !!!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th Sep 2008 15:41
It's doable, and it's not difficult really.

All the information you need to do this is in Mikes post 'New Tutorial For Dark GDK - Loading Custom Media '.

Hayer
18
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 25th Sep 2008 23:52
Oh-h, thanks, haven't see that one before, going to read it now

Hayer
18
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 26th Sep 2008 00:11
Can find the
SetNewObjectFinalProperties
SetTexture

What are they prototypes?

Currently my code is:


Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 26th Sep 2008 05:49
I dont know why the commands wouldnt work, can only suggest that you check the case of the letters, make sure nothing is mistyped, if that isnt the problem, search through the headers for GDK and see if u can find the actual function prototype listed somewhere in there..(also check there arent any other commands you need to call on your "new object" to set it up before you call the final properties command, it might just return if it detects the object isnt setup completely)

To do what you are doing though, I cant say as ive not tried it, but do you think it could be alot easier to build a mesh from memblocks, pass the memblocks a trianglelist ? (i know you said in the top post you didnt want to use memblocks and thats cool, im just curious why. I havent played much with making custom meshes from memblocks, I dont know what/if there are drawbacks to it.)

If it ain't broke.... DONT FIX IT !!!
Hayer
18
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 26th Sep 2008 15:06 Edited at: 26th Sep 2008 16:46
Ah-h, sorry, my mistake got late last night, didn't see my typo.

It should be


Why I won't use memblocks:
1. I want to check if this way is faster.
2. I want to learn something new.

Edit:
New problem

Why won't this render?


IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Sep 2008 19:27
It won't render anything because arrays decay into pointers when passed to functions.



Basically, when you see '<type> var[]' in a function declaration, then read it as '<type>* var'. If you want to know the size of the array within your function, then pass it as an argument.

hayer_p
16
Years of Service
User Offline
Joined: 24th Sep 2008
Location: Norway, Trondheim
Posted: 27th Sep 2008 01:34
uhm-m..... Could u re-write my code so I can compare with the old one?
I don't get exactly what you are trying to say <.<

WTF is this textarea used for? <.< Signature? WTF is that?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Sep 2008 03:58
It's easy - add another parameter to your hyr_CreateNewObject function so that you can pass in the size of the arrays:


Then change your code to call that:


I haven't run the code so you'll need to try it.

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 27th Sep 2008 12:24
won't render
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Sep 2008 14:20
It's being culled - you are looking at the back of the triangle. Either reverse a pair of points, or disable culling on the object.

I chose to disable culling:


Hayer
18
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 27th Sep 2008 17:41
Got the basics working now.

But why won't this render an cube/box?


IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Sep 2008 18:00
Maybe because 4 points on their own don't make a box.

A box is made up from 2 polys. You can create that by either providing 6 points in your existing code, or by changing your code to provide 4 points and 6 indices - this last way will effectively give you 'welded vertices' you talk about in your first post.

Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 27th Sep 2008 18:07
Uh, could you explain what indices are? I'm not much into 3D modeling, so I don't know what they are.
Hayer
18
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 27th Sep 2008 18:09
Well,
Changed this part:
SetupMeshFVFData( pMesh , D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1, NumberOfVertices , 0);

to this:
SetupMeshFVFData( pMesh , D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1, NumberOfVertices , 6);

Still no boxes?

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Sep 2008 18:39
Of course not. You've create an index array, but haven't populated it.

You use the index array to specify which vertex to use for each point, with each group of 3 indices specifying a single poly (eg, (0, 1, 2), (1, 3, 2) - that may not be correct for your points).

You need to provide the values for either:
- 6 vertices,
- or 4 vertices and 6 indices.

Hayer
18
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 27th Sep 2008 23:29 Edited at: 27th Sep 2008 23:34
Just to make things clear;

The iOffset is the index of the vertex created with the SetupStandardVertex and the list should be

Vertex 1 - Index 1
Vertex 2 - Index 2
Vertex 3 - Index 3
Vertex 4 - Index 4
Vertex 5 - Index 5
so on

Or am I completely off-track? (Some thing that I am very often)


Edit :
Looks like I'm wrong again <.<
I'll do some googeling...

Found some great(In my opinion) examples at
http://www.chadvernon.com/blog/tutorials/managed-directx-2/vertex-and-index-buffers/

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Sep 2008 01:23 Edited at: 28th Sep 2008 19:14
Numbering is from 0, in the same way that array entries are numbered.

The first diagram on that page show what I was talking about in my previous post:


On the left are 6 vertices, no index buffer.
On the right are 4 vertices with 6 indices - this is the 'welded' one.

Attachments

Login to view attachments
hayer_p
16
Years of Service
User Offline
Joined: 24th Sep 2008
Location: Norway, Trondheim
Posted: 28th Sep 2008 01:37
I know, I know..
I just wound out what Vertex index are, didn't know before I read trough that page

Thanks for the help IanM

WTF is this textarea used for? <.< Signature? WTF is that?
Hayer
18
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 28th Sep 2008 18:19
So how would/where do I feed it with my index-array?

bool SetupStandardVertex ( DWORD dwFVF, BYTE* pVertex, int iOffset, float x, float y, float z, float nx, float ny, float nz, DWORD dwDiffuseColour, float tu, float tv );

iOffset = The index of the vertex.
Like vertex 1 = 1 , 2 = 2, 3 = 3.
And SetupStandardVertex is called once per vertex so where do I feed it with my index-array, because atm my index array is larger then my vertex array.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Sep 2008 19:17
You just need to fill out the array pIndices within the mesh.

Using the diagram again, here's the code that builds the index array for the right hand side:


Hayer
18
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 29th Sep 2008 19:30
Here is my function:

Here is the code I use to make the vertex and index data:


It's supposed to render an matrix-like model with 3x4 "squares"..
But it doesn't render anything :- /

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Sep 2008 15:06
Get your code to produce a single 4-vertex plain first, then get it to produce a two-column one, then a 2x2 etc. Once you have it working for those three combinations, you're likely to have it right for any size.

I found that drawing it out and numbering the vertices helped an awful lot when producing the same kind of code for my plug-ins.

Hayer
18
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 30th Sep 2008 18:01
Well, thinks it is something wrong with the function about it not setting the index-data

Please, have a look


This is how I write index and vertex data and pass it to the function


IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Sep 2008 19:19
Quote: "int iArray[5];"

2 poly's needs an index of 6 integers, not 5.

Quote: " iArray[0] = 1;
iArray[1] = 2;
iArray[2] = 4;
iArray[3] = 2;
iArray[4] = 3;
iArray[5] = 1;"


The values you should be assigning need to be in the same range as the vertices you are referring to - ie, 0 to 3, not 1 to 4.

Hayer
18
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 30th Sep 2008 19:39 Edited at: 30th Sep 2008 19:40
Yeh, but my array starts at 0
Or should I start at 1?

Edit:
Well

Writing data like this seems to work, so I'll re-do some of my functions, thanks for helping me so much and quick

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Sep 2008 20:14
No.

When you declare an array in C++, you specify the number of items. You need 6. When you access them, you number them from 0, ie your index array is accessed using numbers 0 through to 5.



Hayer
18
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 30th Sep 2008 20:57 Edited at: 30th Sep 2008 23:34
Well, check my algorithm for writing vertex and index data and they work as they should.

This is my current code:


But it wouldn't render anything else then me debug output >.<

EDIT:
Now the code have started to return an error about mem_alloc


Can anyone help me out please? (I think im driving IanM nuts)

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Oct 2008 01:21
Quote: " n0_simpleVertex vArray[4];
int iArray[6];
vArray[1].x = 0; vArray[0].y = 0; vArray[0].z = 0;
vArray[2].x = 50; vArray[1].y = 50; vArray[1].z = 0;
vArray[3].x = 50; vArray[2].y = 0; vArray[2].z = 0;
vArray[4].x = 0; vArray[3].y = 50; vArray[3].z = 0;

iArray[1] = 1;
iArray[2] = 2;
iArray[3] = 4;
iArray[4] = 2;
iArray[5] = 3;
iArray[6] = 1;"


Did you read my previous post? At all?

Arrays are numbered from 0. Your code is overwriting values stored on the stack.

Hayer
18
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 1st Oct 2008 18:17 Edited at: 1st Oct 2008 19:21
EDIT:

Nevermind...

Running this code:


U can see that the object is rendered, but some parts of it seems to be gone.. I'll blame my index data for that.

So, it is my index-data, if not it is?

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Oct 2008 19:38
There's definitely something wrong with your index data.

This 'iArray[4] = 1;' should be this 'iArray[4] = 3;' at the very least.

If you are missing one of the two polys, then determine which one it is and simply swap two of the index values for that poly - which of the 3 you swap doesn't matter to DX, but pick the one that makes it easier to generate when you automate.

Login to post a reply

Server time is: 2024-09-30 07:22:05
Your offset time is: 2024-09-30 07:22:05