Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TGAColor expects an array and not integer arguments #142

Open
tsadarsh opened this issue Jul 17, 2024 · 5 comments
Open

TGAColor expects an array and not integer arguments #142

tsadarsh opened this issue Jul 17, 2024 · 5 comments

Comments

@tsadarsh
Copy link

Compiling my mesh.cpp throws the following error in at this line:

const TGAColor white = TGAColor(255, 255, 255, 255);
 error: no matching function for call to ‘TGAColor::TGAColor(int, int, int, int)’
    6 | const TGAColor white = TGAColor(255, 255, 255, 255);
tgaimage.h:23:8: note: candidate: ‘constexpr TGAColor::TGAColor()’
   23 | struct TGAColor {
      |        ^~~~~~~~
tgaimage.h:23:8: note:   candidate expects 0 arguments, 4 provided
tgaimage.h:23:8: note: candidate: ‘constexpr TGAColor::TGAColor(const TGAColor&)’
tgaimage.h:23:8: note:   candidate expects 1 argument, 4 provided
tgaimage.h:23:8: note: candidate: ‘constexpr TGAColor::TGAColor(TGAColor&&)’
tgaimage.h:23:8: note:   candidate expects 1 argument, 4 provided

Going through the definition of TGAColor in tgaimage.h it is very clear that it expects an array:

struct TGAColor {
    std::uint8_t bgra[4] = {0,0,0,0};
    std::uint8_t bytespp = 4;
    std::uint8_t& operator[](const int i) { return bgra[i]; }
};

So shouldn't TGAColor(255, 255, 255, 255); be changed to TGAColor({255, 255, 255, 255}); in the Wiki pages too?

Doing so compiles the program successfully without any errors. Is this an actual bug or am I not understanding something?

@digitsensitive
Copy link

Hello @tsadarsh
The definition of the struct TGAColor looks different in the tgaimage.h I loaded up from the tinyrenderer repository. Which tgaimage.h are you using?

@tsadarsh
Copy link
Author

I am referring to the current (master) branch. Here is the file tgaimage.h.

@digitsensitive
Copy link

@tsadarsh I see. So this is the problem, why the code does not work, because this is the wrong tgaimage.h file you are referring. If you look at the README.md file @ssloy writes:

... The entire code is available on github, and [here](https://github.com/ssloy/tinyrenderer/tree/909fe20934ba5334144d2c748805690a1fa4c89f) you will find the source code I give to my students.

So no, I do not think that the Wiki needs any changes. This just in case you meant the README.md file.

And yes, you are right with the code change. Just a detail: I think you should use curly brackets to init a struct, like this:

const TGAColor white = TGAColor{{255, 255, 255, 255}};

@ssloy
Copy link
Owner

ssloy commented Jul 25, 2024

It would make sense to add the corresponding constructor to the TGAColor class. Will once I have access to a computer

@tsadarsh
Copy link
Author

Thank you @digitsensitive for the clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants