Using a variable with CUSTOMVERTEX in C++

Chaotic42

Lifer
Jun 15, 2001
35,382
2,501
126
Hey all.

I'm trying to make a triangle with random vertices appear on the screen using DX8.1 It's just an exercise, so please don't give me other ways to make triangles. I need it to work with this function.

Anyway, it works well if I do something like this:
-
CUSTOMVERTEX triangleVertices[] =
{
{320.0f, 120.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(x,y,z),},
{420.0f, 320.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(z,y,x),},
{12.0f, 320.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(y,x,z),},

};
-

However, it draws nothing if I do this:
-
CUSTOMVERTEX triangleVertices[] =
{

{320.0f, 120.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(x,y,z),},
{420.0f, 320.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(z,y,x),},
{e, 320.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(y,x,z),},


};
-

Where e is a float, given a random value between 0 and 1289.0.

What am I doing incorrectly?
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
A range thing? Tried setting e to 12.0 to see if at least that works?

btw, I have no knowledge of dx or d3d, but do they really take floats, not doubles?
 

Chaotic42

Lifer
Jun 15, 2001
35,382
2,501
126
Originally posted by: BingBongWongFooey
A range thing? Tried setting e to 12.0 to see if at least that works?

btw, I have no knowledge of dx or d3d, but do they really take floats, not doubles?

If I try to make e a double, I get this warning:

-
C:\Documents and Settings\Chaotic42\My Documents\C\TRIANGLEAPP2.CPP(204) : warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
-

I still get the same problem.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
I assume you've set a breakpoint or used a trace macro to make sure e has a sane value at exactly that line?

You could be doing something silly like having a nearer-scope e hiding the e that is properly initialized.

Or a buffer overrun could be trashing the stack between initialization and this line.