opengl 4函数的未定义参考(c ++)

时间:2014-01-17 21:02:40

标签: c++ opengl sdl codeblocks mingw32

我设法创建了一个明显有效的openGL上下文和一个窗口,但是当我尝试使用openGL 4中的函数时,它给了我一个未定义的引用错误。 (顺便说一句,我正在使用SDL)这就是我所拥有的:

(graphics.h中)

#define GL4_PROTOTYPES 1
#define GL_GLEXT_PROTOTYPES 1
#include <SDL.h>
#include <gl/glcorearb.h>
#include <SDL_opengl.h>

class OpenGLContext {
public:
OpenGLContext(void); // Default constructor
~OpenGLContext(void); // Destructor for cleaning up our application
void reshapeWindow(int w, int h); // Method to get our window width and height on resize

unsigned int vaoID[1]; // Our Vertex Array Object
unsigned int vboID[1]; // Our Vertex Buffer Object

void renderScene(); // Render scene (display method from previous OpenGL tutorials)
void createSquare(); // Method for creating our squares Vertex Array Object

private:
int windowWidth; // Store the width of our window
int windowHeight; // Store the height of our window

protected:
HGLRC hrc; // Rendering context
HDC hdc; // Device context
HWND hwnd; // Window identifier
};

(graphics.cpp)

#include "graphics.h"

SDL_Window *sdlWindow; //window program displays in

OpenGLContext::OpenGLContext()
{
    windowWidth=600;
    windowHeight=400;
        //set up SDL with OpenGL
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); //set OpenGL profile
    SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 4 ); //set OpenGL version

    sdlWindow = SDL_CreateWindow("Test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, windowWidth, windowHeight, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); //create window with support for OpenGL
    SDL_GL_CreateContext(sdlWindow); //create OpenGL context
    SDL_GL_SetSwapInterval(true); //set VSync
}

OpenGLContext::~OpenGLContext(void) {
SDL_GL_DeleteContext(sdlWindow);
}

void OpenGLContext::renderScene()
{
    SDL_GL_SwapWindow(sdlWindow);
}

void OpenGLContext::createSquare()
{

float* vertices = new float[18];  // Vertices for our square

vertices[0] = -0.5; vertices[1] = -0.5; vertices[2] = 0.0; // Bottom left corner
vertices[3] = -0.5; vertices[4] = 0.5; vertices[5] = 0.0; // Top left corner
vertices[15] = 0.5; vertices[16] = 0.5; vertices[17] = 0.0; // Top Right corner


glGenVertexArrays(1, &vaoID[0]); // Create our Vertex Array Object
glBindVertexArray(vaoID[0]); // Bind our Vertex Array Object so we can use it

glGenBuffers(1, vboID); // Generate our Vertex Buffer Object
glBindBuffer(GL_ARRAY_BUFFER, vboID[0]); // Bind our Vertex Buffer Object
glBufferData(GL_ARRAY_BUFFER, 18 * sizeof(GLfloat), vertices, GL_STATIC_DRAW); // Set the size and data of our VBO and set it to STATIC_DRAW

glVertexAttribPointer((GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0); // Set up our vertex attributes pointer

glEnableVertexAttribArray(0); // Disable our Vertex Array Object
glBindVertexArray(0); // Disable our Vertex Buffer Object
delete [] vertices; // Delete our vertices from memory
}

和main.cpp,我假设我不应该包括,因为它与问题无关。

0 个答案:

没有答案