I have a class where, within a non-static method, I want to make a call to another non-static call. However, in doing so, Visual Studio already gives this alert: "A reference to a non-static member must be relative to the specific object."
The point is that I'm calling the method from the same class, inside itself. In Java I do this without having to declare an instance of the class itself inside it (this would be a dumb redundancy).
How to solve this?
Here are my methods:
Method that is called:
//4- Cria os vértices e seu VBO e VAO. Define a cor a partir de um Uniform
void SceneManager::setupScene()
{
GLuint VBO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
// Position attribute
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
glEnableVertexAttribArray(0);
glBindVertexArray(0);
GLint colorLoc = glGetUniformLocation(shader->Program, "color");
//assert(colorLoc > -1);
glUseProgram(shader->Program);
glUniform4f(colorLoc, 1.0f, 0.0, 0.2f, 1.0f);
Calling method:
void SceneManager::key_callback(GLFWwindow * window, int key, int scancode, int action, int mode)
{
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE);
if (key >= 0 && key < 1024)
{
if (action == GLFW_PRESS)
keys[key] = true;
else if (action == GLFW_RELEASE)
keys[key] = false;
}
// O ERRO É SINALIZADO PELA IDE AQUI: QUANDO EU CHAMO O SETUPSCENE
setupScene();
switch (key)
{
case 65: //tecla A
case 97: //tecla a
vertices[0] = vertices[0]--;
break;
case 68: //tecla D
case 100: //tecla d
cout << "direita" << endl;
break;
case 83: //tecla S
case 115: //tecla s
cout << "baixo" << endl;
break;
case 87: //tecla W
case 119: //tecla w
cout << "cima" << endl;
}
}
In an earlier method, within the same class, setupScene () was already being called, without any error. Why in the other method accuse this error? ::
*2 -INICIALIZA A JANELA GRÁFICA, INICIA O MÉTODO addShader() BUSCA OS DOIS SHADERS E SALVA NUMA VARIÁVEL,
, INICIA O MÉTODO setupScene(), que cira o VBO e VAO dos vértices e define a cor via Uniform*/
void SceneManager::initializeGraphics()
{
// Init GLFW
glfwInit();
// Create a GLFWwindow object that we can use for GLFW's functions
window = glfwCreateWindow(width, height, "Hello Transform", nullptr, nullptr);
glfwMakeContextCurrent(window);
// Set the required callback functions
glfwSetKeyCallback(window, key_callback);
//Setando a callback de redimensionamento da janela
glfwSetWindowSizeCallback(window, resize);
// Set this to true so GLEW knows to use a modern approach to retrieving function pointers and extensions
glewExperimental = GL_TRUE;
// Initialize GLEW to setup the OpenGL Function pointers
glewInit();
// Build and compile our shader program
addShader("../shaders/transformations.vs", "../shaders/transformations.frag");
//setup the scene -- LEMBRANDO QUE A DESCRIÇÃO DE UMA CENA PODE VIR DE ARQUIVO(S) DE
// CONFIGURAÇÃO
setupScene();
resized = true; //para entrar no setup da câmera na 1a vez
}