Below is the code. I believe AtoR4 proc was posted on this forum awhile back by Randall(?)..
The problem is, my mesh drawing is all messed up.

How could I print out what is stored at the address in QWT and convert to string so I can see its value?
I am using REAL4's by the way..



LOCAL QWT:DWORD

pushad
invoke StrTok, edx, ADDR vspc
pushad
invoke AtoR4, ADDR bRet, ADDR QWT
popad

push QWT
mov eax,EL
pop [vObj.FVX.x+eax]



My StrTok() function works perfectly. bRet is my static null-terminated string holder, eg:

.data
bRet db 80 dup(0)

At time of function call, bRet contains "-45.26351",0
I push the address value of QWT into the stack and pop it back out onto the struct (memory location).


structure is:
.data
FVX struct ;vertices, if type=QUAD then glF4 is populated
x REAL4 0.0
y REAL4 0.0
z REAL4 0.0
FVX ends
SIZEOFFVX DWORD sizeof FVX
Posted on 2004-01-21 21:50:10 by drarem
I have figured it is somewhere else - I did the following to verify the correct numbers were in the correct arrays:




.data
FVX struct ;vertices, if type=QUAD then x3,y3,z3 are populated
x REAL4 0.0
y REAL4 0.0
z REAL4 0.0
FVX ends
SIZEOFFVX EQU sizeof FVX



pushad
fld [vObj.FVX.x+edx]
fstp real8test
invoke FloatToStr, real8test, ADDR alf
invoke wsprintf, ADDR fmtTxt, ADDR alf2, ADDR alf
invoke MessageBox,NULL,ADDR fmtTxt, ADDR fmtTxt, MB_OK
popad


Below is the loading of the structure:


invoke StrTok, edx, ADDR vspc

pushad
;;;; replaced with StrToFloat invoke AtoR4, ADDR bRet, ADDR QWT
invoke StrToFloat, ADDR bRet, ADDR QWT
popad

fld QWT ;QWT is a REAL8 local variable

push EL ;index of array, EL=EL+sizeof FVX
pop eax
fstp [vObj.FVX.x+eax]

I got back the expected numbers when converting to QWORD (REAL8) to convert to a string to display..

now my question is, since it appears to be ok when converting to REAL8, calling

glVertex3F REAL4,REAL4,REAL4 <===== the real4 format will be handled nicely by the opengl functions

right? It does seem to be an obvious question but I am trying to figure out where I am going wrong and I think

it might be in the face-drawing loop.
Posted on 2004-01-26 11:50:33 by drarem
It's still not making sense..


FVX struct
x REAL4 0.0
y REAL4 0.0
z REAL4 0.0
FVX ends
SIZEOFFVX EQU sizeof FVX

1.) SIZEOFFVX = 12 ?? Is that right? Ollydbg sayz so..

2.) Can you convert REAL8 to REAL4 AND vice-versa by FLD/FSTP??? or does the downward swing lose something? NOTE: average number looks something like: -35.23421 or 43.676 so it shouldn't I would think?

eg.. is this valid?
FLD real4var
FSTP real8var ;convert real4 to real8

FLD real8var
FSTP real4var ;convert real8 down to real4 so glVertex3f won't laff at me..
Posted on 2004-01-27 13:43:54 by drarem
1) REAL4 = 4 bytes. So the size of the struct is 12.
2) Not too sure, but I think if you convert real8 to real4 there would be a loss of precision. If I am not wrong, what you are doing is correct (regarding the fld and fstp)
Posted on 2004-01-28 07:11:59 by roticv
Thanks, Roticv - after going through my code and doing all sorts of trial and errors, really frying some brain cells,
I think I have found my problem (via memproof, observation, and patience) -

I must be doing this wrong:



invoke GetProcessHeap
invoke HeapAlloc,eax,HEAP_ZERO_MEMORY,360000*sizeof DWORD
mov [FO],eax ;the actual file object (3d object data to load into for drawing)

invoke GetProcessHeap
invoke HeapAlloc,eax,HEAP_ZERO_MEMORY,4096*sizeof FVX ;up to 4096 of vertices
mov [vObj],eax ;move address into vObj variable

invoke GetProcessHeap
invoke HeapAlloc, eax, HEAP_ZERO_MEMORY,4096*sizeof FFC
mov [fObj],eax ;face pointer object (glF1,glF2,glF3{...,glF4})


When I go to HeapFree the other two objects out of three (FO, vObj, and fObj), memproof tells me that the second two trying to Free up are invalid memory pointers, plus when I create the faces it tends to mess up the vertices, which leads me to believe both vertices and face variables point to the same memory location.

When I only run the build vertices and manually use the face to access the vertex, the vertex is fine.. however when I run the faces after building the vertices from the file, some of the vertices get corrupted ending up something like 2.1423exp-45 instead of 6.69181.. the reverse happens if I reverse it, build the faces first then do the vertices - the faces get corrupted.

Like when I add to the first face (glF1) as below:



invoke StrTok, edx, ADDR fspc

pushad
invoke atodw, ADDR bRet
mov RL,eax
popad

fld RL
mov eax,EL
fstp [fObj.FFC.glF1+eax]


It goes nowhere NEAR the vertices in this subroutine yet somehow manages to screw them up.. how?
Posted on 2004-01-29 07:43:51 by drarem