我正在尝试构建一个拒绝工作的简单openGL和SDL程序。
我正在使用最新的nvidia驱动程序(我记得还记得285.something),我使用mingw进行编译。我使用的计算机运行Windows7。我对mingw的了解有限,因此这可能是一个非常简单的链接错误。
我正在使用的SDL版本是1.2(我应该升级到1.3吗?)
最初,一切正常,但是我只是通过SDL打开opengl窗口。这是原始makefile的代码
all:
g++ -o sdlGL.exe esg.cpp tiletest.cpp -lmingw32 -lSDLmain -lSDL -lopengl32 -lglu32
Run Code Online (Sandbox Code Playgroud)
这些是被称为2个功能
void init_sdl(int width, int height) {
//Start SDL
if(SDL_Init(SDL_INIT_EVERYTHING) != 0) {
fDebug << "Failed to init SDL" << std::endl;
quit(1);
}
//Set SDL attrib.
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
//Set SDL video mode
if( SDL_SetVideoMode(width, height, 0, SDL_OPENGL) == 0 ) {
fDebug << "Failed to set SDL video mode" << std::endl;
quit(1);
}
}
//Initializes OpenGL
void init_opengl(int width, int height, bool alpha) {
// Set the OpenGL state after creating the context with SDL_SetVideoMode
glClearColor( 0, 0, 0, 0 );
glClear(GL_COLOR_BUFFER_BIT);
glEnable( GL_TEXTURE_2D ); // Need this to display a texture
if(alpha) {
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0, width, height, 0, -1, 1 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}
Run Code Online (Sandbox Code Playgroud)
现在为包含物:
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_opengl.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
Run Code Online (Sandbox Code Playgroud)
使用该代码,一切工作正常。然后我添加了一些功能来处理着色器和着色器程序
void CreateShader(GLenum eShaderType, const std::string &strShaderFile, std::vector<GLuint> &shaderList) {
GLuint shader = glCreateShader(eShaderType);
const char *strFileData = strShaderFile.c_str();
glShaderSource(shader, 1, &strFileData, NULL);
glCompileShader(shader);
GLint status;
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
shaderList.push_back(shader);
}
void ClearShader(std::vector<GLuint> &shaderList) {
std::for_each(shaderList.begin(), shaderList.end(), glDeleteShader);
}
GLuint CreateProgram(const std::vector<GLuint> &shaderList) {
GLuint program = glCreateProgram();
for(size_t iLoop = 0; iLoop < shaderList.size(); iLoop++)
glAttachShader(program, shaderList[iLoop]);
glLinkProgram(program);
GLint status;
glGetProgramiv (program, GL_LINK_STATUS, &status);
for(size_t iLoop = 0; iLoop < shaderList.size(); iLoop++)
glDetachShader(program, shaderList[iLoop]);
return program;
}
Run Code Online (Sandbox Code Playgroud)
现在,编译器抱怨说在此范围内未声明glCreateShader,glShaderSource,glCompileShader,glGetShaderiv,glDeleteShader,glCreateProgram,glAttachShader,glLinkProgram,glGetProgramiv和glDetachShader。
我想我需要包括高兴或高兴(对吗?),所以我高兴了。然后,我将-glew32添加到我的makefile中,并将glew.h添加到我的包含文件中
#include "GL/glew.h"
Run Code Online (Sandbox Code Playgroud)
现在,编译器为glew.h列出了大量错误,例如----没有命名类型,并且----在此范围内未声明。
我不知道该怎么办才能解决此问题。我应该补充一点,就是我对openGL的经验不足。
GLEW处理#includeGL标头的特定于平台的,因此您不再需要SDL_opengl.h。它还是#include适当的GLU标头,因此您也不需要。
正如Xavier所指出的那样#include <GL/glew.h>。如果我没记错的话,它往往与冲突windows.h。
| 归档时间: |
|
| 查看次数: |
5034 次 |
| 最近记录: |