为什么这个错误变成(C2664错误C ++ Visual Studio)
why this error become (C2664 error c++ Visual Studio)
我正在尝试修改一个程序.在2015 Visual Studio中实现。 在Visual Studio 2019中打开项目后,会出现以下类型的许多错误。
Severity Code Description Project File Line Suppression State Error C2664 'Model::Model(Model &&)': cannot convert argument 1 from 'const > char [24]' to 'GLchar *' OpenGl Severity Code Description Project File Line Suppression State Message Conversion from string literal loses const qualifier (see /Zc:strictStrings) OpenGl
该行中形成的错误:
// Create a GLFWwindow object that we can use for GLFW's functions
GLFWwindow *window = glfwCreateWindow( WIDTH, HEIGHT, "LearnOpenGL",
nullptr, nullptr );
if ( nullptr == window )
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate( );
return EXIT_FAILURE;
}
glfwMakeContextCurrent( window );
glfwGetFramebufferSize( window, &SCREEN_WIDTH, &SCREEN_HEIGHT );
// Set the required callback functions
glfwSetKeyCallback( window, KeyCallback );
glfwSetCursorPosCallback( window, MouseCallback );
// GLFW Options
glfwSetInputMode( window, GLFW_CURSOR, GLFW_CURSOR_DISABLED );
// 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
if ( GLEW_OK != glewInit( ) )
{
std::cout << "Failed to initialize GLEW" << std::endl;
return EXIT_FAILURE;
}
// Define the viewport dimensions
glViewport( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );
// OpenGL options
glEnable( GL_DEPTH_TEST );
// Setup and compile our shaders
Shader shader( "res/shaders/modelLoading.vert",
"res/shaders/modelLoading.frag" );
// Load models
Model ourModel("res/models/nanosuit.obj");
// Draw in wireframe
//glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
glm::mat4 projection = glm::perspective( camera.GetZoom( ), ( float
)SCREEN_WIDTH/( float )SCREEN_HEIGHT, 0.1f, 100.0f );
// Game loop
while( !glfwWindowShouldClose( window ) )
{
// Set frame time
GLfloat currentFrame = glfwGetTime( );
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
// Check and call events
glfwPollEvents( );
DoMovement( );
// Clear the colorbuffer
glClearColor( 0.05f, 0.05f, 0.05f, 1.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
shader.Use( );
glm::mat4 view = camera.GetViewMatrix( );
glUniformMatrix4fv( glGetUniformLocation( shader.Program, "projection"
), 1, GL_FALSE, glm::value_ptr( projection ) );
glUniformMatrix4fv( glGetUniformLocation( shader.Program, "view" ),
1,
GL_FALSE, glm::value_ptr( view ) );
// Draw the loaded model
glm::mat4 model;
model = glm::translate( model, glm::vec3( 0.0f, -1.75f, 0.0f ) ); //
Translate it down a bit so it's at the center of the scene
model = glm::scale( model, glm::vec3( 0.2f, 0.2f, 0.2f ) ); // It's a
bit too big for our scene, so scale it down
glUniformMatrix4fv( glGetUniformLocation( shader.Program, "model" ),
1, GL_FALSE, glm::value_ptr( model ) );
ourModel.Draw( shader );
// Swap the buffers
glfwSwapBuffers( window );
}
glfwTerminate( );
return 0;
}
// Moves/alters the camera positions based on user input
void DoMovement( )
{
// Camera controls
if ( keys[GLFW_KEY_W] || keys[GLFW_KEY_UP] )
{
camera.ProcessKeyboard( FORWARD, deltaTime );
}
if ( keys[GLFW_KEY_S] || keys[GLFW_KEY_DOWN] )
{
camera.ProcessKeyboard( BACKWARD, deltaTime );
}
if ( keys[GLFW_KEY_A] || keys[GLFW_KEY_LEFT] )
{
camera.ProcessKeyboard( LEFT, deltaTime );
}
if ( keys[GLFW_KEY_D] || keys[GLFW_KEY_RIGHT] )
{
camera.ProcessKeyboard( RIGHT, deltaTime );
**strong text** }
}
// Is called whenever a key is pressed/released via GLFW
void KeyCallback( GLFWwindow *window, int key, int scancode, int
action, int mode )
{
if ( GLFW_KEY_ESCAPE == key && GLFW_PRESS == action )
{
glfwSetWindowShouldClose(window, GL_TRUE);
}
if ( key >= 0 && key < 1024 )
{
if ( action == GLFW_PRESS )
{
keys[key] = true;
}
else if ( action == GLFW_RELEASE )
{
keys[key] = false;
}
}
}
void MouseCallback( GLFWwindow *window, double xPos, double yPos )
{
if ( firstMouse )
{
lastX = xPos;
lastY = yPos;
firstMouse = false;
}
GLfloat xOffset = xPos - lastX;
GLfloat yOffset = lastY - yPos; // Reversed since y-coordinates go from
bottom to left
lastX = xPos;
lastY = yPos;
camera.ProcessMouseMovement( xOffset, yOffset );
}
错误正好在 荷载模型 Model ourModel("res/models/nanosuit.obj"(;
您可以将模型名称作为非常量 C 字符串传递:
char tmp[] = "res/models/nanosuit.obj";
Model ourModel(tmp);
相关文章:
- Visual Studio mkl_link_tool.exe链接错误
- 尝试使用继承和模板实现CRTP.Visual Studio正在生成编译器错误
- 设置 Visual Studio for MPI: 找不到标识符错误
- 将QT项目导入Visual Studio 2019会给我带来很多LNK2001错误
- 第三方 API 中的编译错误 - Visual Studio
- 在函数中使用 const int size 参数创建数组会在 Visual Studio 中抛出错误 C++:表达式的计
- 使用Visual Studio在虚幻引擎中创建一个新的类c ++给了我太多的错误
- Visual Studio 2019在内置库中存在错误
- 内部编译器错误Visual Studio Community 2017与SFML API
- 交叉编译错误 Visual Studio C++
- 默认参数值错误 [Visual C++ 2008 中的错误?
- 什么是 ?和 @ 符号演示此编译器错误?- Visual Studio 2013 Compiler.
- 错误:Visual Studio中没有为opencv_world310.dll加载符号
- 未处理的异常错误 Visual Studio 2012 和 Allegro 4
- 危险的错误 Visual c++ 2005
- c++链接器错误(Visual Studio c++ 2010)
- 如何修复msvcp120 .dll错误Visual Studio 2015
- libpng错误:读取错误(Visual Studio 2010)
- 未处理的异常错误visual studio 2010 c++ (open gl)
- 使用不在根项目目录上的源文件(包括在搜索路径中的文件)时发生链接错误(Visual C++)