i get an error on 'Pixels[X] [Y] = Color;': "invalid types 'unsigned int[unsigned int]' for array subscript".
how can i fix the code?
'PosX' and 'PosY' are float types
Pixels is a pointer to unsigned int, but you're trying to dereference it twice. If you need to flatten a 2D coordinate for rectangular data, you'd do something like:
1 2
size_t index = width * y + x;
Pixels[index] = value;
PS: Passing Pixels as a reference is unnecessary since you never overwrite the value of Pixels itself.
'DrawLine3D()' don't recive size parameters.
if i do 'void DrawLine3D(unsigned int Pixels[],'.. works but the array have only 1 dimension... but how i change for 2 dimensions?
"unsigned int Pixels[]" and "unsigned int* Pixels" as function parameters mean the same exact thing, it's just syntax sugar to use the [].
As seen in your other thread, the Win32 call StretchDIBits inevitably expects the lpBits data to be representable as one contiguous 1D array. So you can cast the 2D array to fake it as a 1D pointer, or you could just have a 1D array to begin with.(*) The latter seems simpler to me, but I guess either way works.
You own the DrawLine3D function. Add a parameter that tells the function what the width is. Pass in ConsoleWidth tp DrawLines3D, then you can do pixels[y * ConsoleWidth + x] = Color;
With array, no. You need the non-inner dimension so the compiler knows the pointer offsets.
With vector, yes. You can pass a vector of vectors as a parameter, and then query the .size() of each inner vector to know the width. But this is (1) less efficient since each vector is a separate allocation, and (2) not compatible with what StretchDIBits requires, since it requires one contiguous array.
What is so bad about adding a parameter to DrawLine3D, since you are able to change the function signature?
Ganado: "All good suggestions. Only thing that remains is figuring out why Cambalinho doesn't want to pass the width as a parameter, solving all his problems."
i'm sorry... but why not be more automatic and simple? is what i think... i can add more parameters on function... but i need be more simple ;)
thanks to all.. but i'm trying using: std::vector<std::vector<unsigned >> PixelColors{{ConsoleWidth},{ConsoleHeight}};
but when i do:
i get these error when the program terminates\frezes:
"Process returned -1073740940 (0xC0000374) execution time : 0.025 s
Press any key to continue."
i'm doing wrong with 'PixelColors[y][x]' or with 'PixelColors{{ConsoleWidth},{ConsoleHeight}}'?
i did wrong the 2D vector creation: std::vector<std::vector<unsignedint>> PixelColors( ConsoleHeight , std::vector<unsignedint> (ConsoleWidth, 0));
even on value i must use the 'vector'.
now i did another topic for convert 2D vector to void*.
thank you so much for all