我從官方網站下載了oglpg-8th-edition檔案夾,在VS2015包含目錄中添加了oglpg-8th-edition\include,庫目錄也添加了oglpg-8th-edition\lib,然后復制了OpenGL編程指南第八版第一章的triangles.cpp,還在專案里添加了LoadShaders.cpp。
///////////////////////////////////////////////////////////////////////
//
// triangles.cpp
//
///////////////////////////////////////////////////////////////////////
#include <iostream>
using namespace std;
#include "vgl.h"
#include "LoadShaders.h"
enum VAO_IDs { Triangles, NumVAOs };
enum Buffer_IDs { ArrayBuffer, NumBuffers };
enum Attrib_IDs { vPosition = 0 };
GLuint VAOs[NumVAOs];
GLuint Buffers[NumBuffers];
const GLuint NumVertices = 6;
//---------------------------------------------------------------------
//
// init
//
void init(void)
{
glGenVertexArrays(NumVAOs, VAOs);
glBindVertexArray(VAOs[Triangles]);
GLfloat vertices[NumVertices][2] = {
{ -0.90, -0.90 }, // Triangle 1
{ 0.85, -0.90 },
{ -0.90, 0.85 },
{ 0.90, -0.85 }, // Triangle 2
{ 0.90, 0.90 },
{ -0.85, 0.90 }
};
glGenBuffers(NumBuffers, Buffers);
glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
vertices, GL_STATIC_DRAW);
ShaderInfo shaders[] = {
{ GL_VERTEX_SHADER, "triangles.vert" },
{ GL_FRAGMENT_SHADER, "triangles.frag" },
{ GL_NONE, NULL }
};
GLuint program = LoadShaders(shaders);
glUseProgram(program);
glVertexAttribPointer(vPosition, 2, GL_FLOAT,
GL_FALSE, 0, BUFFER_OFFSET(0));
glEnableVertexAttribArray(vPosition);
}
//---------------------------------------------------------------------
//
// display
//
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBindVertexArray(VAOs[Triangles]);
glDrawArrays(GL_TRIANGLES, 0, NumVertices);
glFlush();
}
//---------------------------------------------------------------------
//
// main
//
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutInitWindowSize(512, 512);
glutInitContextVersion(4, 3);
glutInitContextProfile(GLUT_CORE_PROFILE);
glutCreateWindow(argv[0]);
if (glewInit()) {
cerr << "Unable to initialize GLEW ... exiting" << endl;
exit(EXIT_FAILURE);
}
init();
glutDisplayFunc(display);
glutMainLoop();
}
但還是會遇到LNK2001、LNK2019的錯誤:
VS2015資訊:
1> LoadShaders.cpp
1> 正在生成代碼...
1>LIBCMTD.lib(initializers.obj) : warning LNK4098: 默認庫“msvcrtd.lib”與其他庫的使用沖突;請使用 /NODEFAULTLIB:library
1>freeglut_static_vs2010_d.lib(freeglut_init.obj) : error LNK2019: 無法決議的外部符號 _sscanf,該符號在函式 _glutInit 中被參考
1>freeglut_static_vs2010_d.lib(freeglut_main.obj) : error LNK2019: 無法決議的外部符號 _vfprintf,該符號在函式 _fgError 中被參考
1>freeglut_static_vs2010_d.lib(freeglut_main.obj) : error LNK2019: 無法決議的外部符號 ___iob_func,該符號在函式 _fgError 中被參考
1>freeglut_static_vs2010_d.lib(freeglut_display.obj) : error LNK2001: 無法決議的外部符號 ___iob_func
1>freeglut_static_vs2010_d.lib(freeglut_joystick.obj) : error LNK2019: 無法決議的外部符號 __snprintf,該符號在函式 _fghJoystickGetOEMProductName 中被參考
1>msvcrtd.lib(_chandler4gs_.obj) : error LNK2019: 無法決議的外部符號 __except_handler4_common,該符號在函式 __except_handler4 中被參考
1>E:\Charles File\C++\Source File\VS2015\$OpenGL\testing3\Debug\testing3.exe : fatal error LNK1120: 5 個無法決議的外部命令
========== 全部重新生成: 成功 0 個,失敗 1 個,跳過 0 個 ==========
是不是oglpg-8th-edition的freeglut_static_2010.lib和libcmtd.lib有沖突?我用VS2010的libcmtd.lib替換了2015的,錯誤變成了52個!怎么辦?
uj5u.com熱心網友回復:
麻煩各位大神看一下。如果解決了問題,本人將不勝感激!并且我會將具體的配置方法寫到自己的博客中,給使用VS2015的人做參考。uj5u.com熱心網友回復:
把libcmtd.lib這個庫忽略了試試uj5u.com熱心網友回復:
http://www.cnblogs.com/gagugagu/p/5211452.htmluj5u.com熱心網友回復:
vs必須用windows console建立專案,指定庫檔案目錄,因為glut,glew都要window的很多標記。頭檔案不能亂,比如二個glut.h,就完蛋。uj5u.com熱心網友回復:
你可以看看,我的配置方法,有工程原始碼:https://blog.csdn.net/guyuealian/article/details/85262650轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/44243.html
上一篇:plc求救help
下一篇:求這道題的c++的代碼。
