C++ 无法理解为什么我获取GL\u无效\u操作

C++ 无法理解为什么我获取GL\u无效\u操作,c++,opengl,C++,Opengl,我正在创建一个小游戏,我想把东西从类的主循环中去掉 我想画一个绑在玩家身上的图形 //identity matrix Matrix44 model; //set up the model to world transform model.SetTranslation(player.position); //pass a uniform which specifies the color of the player to the fragment sh

我正在创建一个小游戏,我想把东西从类的主循环中去掉

我想画一个绑在玩家身上的图形

    //identity matrix
    Matrix44 model; 

    //set up the model to world transform
    model.SetTranslation(player.position);

    //pass a uniform which specifies the color of the player to the fragment shader
    glUniform3f(colorLocation, player.color._x, player.color._y, player.color._z);

    //pass the model as well 
    glUniformMatrix4fv(transformLocation, 1, GL_FALSE, &model.m[0][0]);

    //draw
    glDrawArrays(GL_TRIANGLES, 0, 36);
这是主循环中的实现。它就像一个符咒。 当我尝试从一个Player类调用相同的函数时,问题就出现了

void Player::drawPlayer(GLint transformLocation, GLint colorLocation)
{   

Matrix44 model;     
model.SetTranslation(position); 

glUniform3f(colorLocation, color._x, color._y, color._z);   
std::cout << glGetError() << std::endl;  <- I get error 1028 here

glUniformMatrix4fv(transformLocation, 1, GL_FALSE, &model.m[0][0]);
std::cout << glGetError() << std::endl;   <- I get error 1028 here

glDrawArrays(GL_TRIANGLES, 0, 36);
std::cout << glGetError() << std::endl;

}
{ std::vector::it迭代器

for (it = levelTiles.begin(); it != levelTiles.end(); ++it)
{
    Matrix44 model;
    GameObject temp = *it;

    model.SetTranslation(temp.position);
    glUniform3f(colorLocation, temp.color._x, temp.color._y, temp.color._z);
    glUniformMatrix4fv(transformLocation, 1, GL_FALSE, &model.m[0][0]);
    glDrawArrays(GL_TRIANGLES, 0, 36);
}

for (it = fallingBlocks.begin(); it != fallingBlocks.end(); ++it)
{
    Matrix44 model;
    GameObject temp = *it;
    model.SetTranslation(temp.position);

    glUniform3f(colorLocation, temp.color._x, temp.color._y, temp.color._z);        
    glUniformMatrix4fv(transformLocation, 1, GL_FALSE, &model.m[0][0]);
    glDrawArrays(GL_TRIANGLES, 0, 36);
}
上面的代码实际上是一样的,但它可以工作。而且这两个类都继承自同一个基类-GameObject。我可以离开它,使用一种变通方法,但它感觉不正确

这是整个主回路:

  ourShader.Use();

    Matrix44 view;
    Matrix44 projection;        

    projection = projection.CreatePerspective(45.f, width / height, 0.1f, 100.f);       

    Vector3 eye(0.f, 0.f, -3.f);
    Vector3 center(0.f, 0.f, 0.f);
    Vector3 up(0.f, 1.f, 0.f);
    view = view.CreateLookAt(eye, center, up);


    GLint transformLocation = glGetUniformLocation(ourShader.Program, "model");
    GLint viewLocation = glGetUniformLocation(ourShader.Program, "view");
    GLint projectionLocation = glGetUniformLocation(ourShader.Program, "projection");
    GLint colorLocation = glGetUniformLocation(ourShader.Program, "cubeColor");

    glUniformMatrix4fv(viewLocation, 1, GL_FALSE, &view.m[0][0]);       
    glUniformMatrix4fv(projectionLocation, 1, GL_FALSE, &projection.m[0][0]);       
    //=====================================================================================

    //
    //draw the player
    //player.drawPlayer(colorLocation, transformLocation);

    // draw the level tiles
    glBindVertexArray(level._VAO);
    level.drawLevelTiles(colorLocation, transformLocation);
    player.drawPlayer(colorLocation, transformLocation);

    glBindVertexArray(0);

    // Swap the screen buffers
    glfwSwapBuffers(window);

欢迎提出任何建议!

比较一下“drawPlayer”的定义和用法`
void Player::drawPlayer(GLint transformLocation, GLint colorLocation)
player.drawPlayer(colorLocation, transformLocation);


您看到参数不匹配了吗?

谢谢您,先生!这就是问题所在。
void Player::drawPlayer(GLint transformLocation, GLint colorLocation)
player.drawPlayer(colorLocation, transformLocation);