• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Using a variable with CUSTOMVERTEX in C++

Chaotic42

Lifer
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?
 
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?
 
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.
 
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.
 
Back
Top