0

I have a problem with my code, and I don't understand why it is not working.

I'm learing to use OpenGL to draw stuff on the screen, and I have gotten pretty far honestly, but I was just messing with a struct to group light properties and I don't know how to proceed.

The struct code is the following:

//outside of main()
struct lightProperties {
    glm::vec3 dirDirection = glm::vec3(-0.2f, -0.3f, -0.5f);
    glm::vec3 dirAmbient = glm::vec3(1.0f);
    glm::vec3 dirDiffuse = glm::vec3(1.0f);
    glm::vec3 dirSpecular = glm::vec3(1.0f);
    float matShininess = 20.0f;
}
//inside the main()
lightProperties light;

I am in the process of including ImGui in my project, so I was setting up all the functions that modified the uniforms. I have this function in particular, written in a header file:

//ImGui_functions.h
void imguiDrawmenu(struct lightProperties* light) {
    ImGui::Begin("OpenGl", NULL ,ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_AlwaysAutoResize |
        ImGuiWindowFlags_NoResize);

    if (ImGui::CollapsingHeader("Directional Light")) {
        ImGui::SliderFloat3("Direction", glm::value_ptr(light->dirDirection), -1.0f, 1.0f);
    }

    ImGui::End();
    ImGui::Render();
    ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}

And then I call the functions inside the main while loop of the program as such:

imguiDrawmenu(&light);

At first, I thought that I just needed to pass the struct as a reference, but it just didn't work for some reason. But then, I realized that the function just recieves a pointer, so when I use the . operator, the program doesn't know that my pointer has member variables, for obvious reasons. I then read about the arrow operator, ->, that supposedly is used to reference member variables of a pointed class/struct, but I don't understand why it is not working.

The error is the following:

C2027 use of undefined type 'lightProperties'

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Beaver
  • 41
  • 4
  • 2
    It's simple. When the compiler sees `lightProperties` in your header file it must have **previously** seen the definition of `lightProperties`. It's up to you to make sure that happens using an appropriate `#include` or by moving your code around. – john Dec 04 '22 at 13:40
  • Looking at your post it's pretty clear you are winging it. No-one has properly explained how to organise your code. You should really study some proper learning material that explains this (like a C++ book). C++ is a very hard language to learn without proper study. – john Dec 04 '22 at 13:42
  • https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list might be a start for you. Also, when things go awry, extract a [mcve]. Chances are the error becomes obvious that way. – Ulrich Eckhardt Dec 04 '22 at 13:55

0 Answers0