hi,
I'm trying to get started with OpenGL in C++ but I'm having constant issues with it, for IDE I have chosen Eclipse with MinGW as my tool chain.
while using MinGW and GLUT works fine I want to make use of the greater functionality OpenGL offers such as VBO's, Shader Programs, etc. all signs seem to point to Glew being the best option and some sources claiming it my only option but for the life of me I keep running into errors,
at the moment this is how the console reports,
I am using a minGW built library, but I've also tried the dll as a library and the pre-built libraries from the glew sourceforge
18:15:36 **** Incremental Build of configuration Debug for project Sample ****
Info: Internal Builder is used for build
g++ -static-libgcc -static-libstdc++ -o Sample.exe main.o -lopengl32 -lglu32 -lfreeglut -lglew32
main.o: In function `ZN4MeshC2Ev':
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:4: undefined reference to `__glewGenBuffers'
main.o: In function `ZN4MeshD2Ev':
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:11: undefined reference to `__glewDeleteBuffers'
main.o: In function `ZN4Mesh4FillEP6VertexPjjjj':
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:29: undefined reference to `__glewBindBuffer'
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:31: undefined reference to `__glewBufferData'
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:32: undefined reference to `__glewBindBuffer'
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:34: undefined reference to `__glewBufferData'
main.o: In function `ZN4Mesh4DrawEv':
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:37: undefined reference to `__glewBindBuffer'
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:38: undefined reference to `__glewBindBuffer'
main.o: In function `main':
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:62: undefined reference to `glewInit@0'
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:65: undefined reference to `glewGetErrorString@4'
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:67: undefined reference to `glewGetString@4'
collect2.exe: error: ld returned 1 exit status
18:15:36 Build Finished (took 127ms)
and here are the files
[spoiler]
header.h
#ifndef SAMPLE_HEADER_H
#define SAMPLE_HEADER_H
#include <GL/glew.h>
#include <GL/glut.h>
#include <stdio.h>
#include <windows.h>
struct Vertex {
public:
float px, py, pz;
Vertex() {
px = py = pz = 0;
}
Vertex(float pX, float pY, float pZ) {
px = pX;
py = pY;
pz = pZ;
}
};
class Mesh {
private:
unsigned int* bufferObjects;
Vertex* vertexData;
unsigned int* indexData;
unsigned int vertexCount;
unsigned int indexCount;
public:
Mesh();
~Mesh();
void Fill(Vertex* vertices, unsigned int* indices, unsigned int vertCount,
unsigned int indCount, GLenum usage);
void Draw();
};
#endif /* HEADER_H_ */
main.cpp
#include "header.h"
Mesh::Mesh() {
glGenBuffers(2, bufferObjects);
vertexData = 0;
indexData = 0;
vertexCount = 0;
indexCount = 0;
}
Mesh::~Mesh() {
glDeleteBuffers(2, bufferObjects);
delete bufferObjects;
bufferObjects = 0;
delete vertexData;
vertexData = 0;
delete indexData;
indexData = 0;
}
void Mesh::Fill(Vertex* vertices, unsigned int* indices, unsigned int vertCount,
unsigned int indCount, GLenum usage) {
if (vertexData != 0)
delete vertexData;
vertexData = vertices;
if (indexData != 0)
delete indexData;
indexData = indices;
vertexCount = vertCount;
indexCount = indCount;
glBindBuffer(GL_ARRAY_BUFFER, bufferObjects[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * vertexCount, vertexData,
usage);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferObjects[1]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * indexCount,
indexData, usage);
}
void Mesh::Draw() {
glBindBuffer(GL_ARRAY_BUFFER, bufferObjects[0]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferObjects[1]);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(Vertex), ((void*) 0));
glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, ((void*) 0));
glDisableClientState(GL_VERTEX_ARRAY);
}
void display() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(-0.5f, -0.5f);
glVertex2f(0.5f, -0.5f);
glVertex2f(0.5f, 0.5f);
glVertex2f(-0.5f, 0.5f);
glEnd();
glFlush();
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutCreateWindow("OpenGL Setup Test");
GLenum err = glewInit();
if (GLEW_OK != err) {
/* Problem: glewInit failed, something is seriously wrong. */
fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
}
fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
[/spoiler]
as far as C++ goes I'm fairly new, I've used it in the past for basic DirectX projects, like a model viewer but not extensively and not with any issues like this which weren't already heavily documented.
I've tried google all I can but I just can't seem to get around it,
Any and all help would be greatly appricieted,
Thanks for reading,
Bombshell