Ok, I hate swapping the thread topic a bit but here’s what I’ve been trying to do. Under the book the first example is as follows:
///////////////////////////////////////////////////////////////////////
//
// 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();
}
With the two headers being in the source code on the website. Here is my makefile:
#OBJS specifies which files to compile as part of the project
OBJS = triangles.cpp
#OBJ_NAME specifies the name of our exectuable
OBJ_NAME = triangles
#CC specifies which compiler we're using
CC = g++
#INCLUDE_PATHS specifies the additional include paths we'll need
INCLUDE_PATHS = -IC:\mingw_dev_lib\freeglut\include
#LIBRARY_PATHS specifies the additional library paths we'll need
LIBRARY_PATHS = -LC:\mingw_dev_lib\freeglut\lib
#COMPILER_FLAGS specifies the additional compilation options we're using
# -w suppresses all warnings
# -Wl,-subsystem,windows gets rid of the console window
COMPILER_FLAGS = -w -Wl,-subsystem,windows
#LINKER_FLAGS specifies the libraries we're linking against
LINKER_FLAGS = -lOpenGL32 -lglu32 -lfreeGLUT
#This is the target that compiles our executable
all : $(OBJS)
$(CC) $(OBJS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME)
With all this I get undefined references as follows:
C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x1c): undefine
d reference to `__glutInitWithExit'
C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x37): undefine
d reference to `__glutCreateWindowWithExit'
C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x52): undefine
d reference to `__glutCreateMenuWithExit'
C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x65): undefine
d reference to `__glewGenVertexArrays'
C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x7f): undefine
d reference to `__glewBindVertexArray'
C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0xa6): undefine
d reference to `__glewGenBuffers'
C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0xc0): undefine
d reference to `__glewBindBuffer'
C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0xdb): undefine
d reference to `__glewBufferData'
C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x135): undefin
ed reference to `LoadShaders'
C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x13e): undefin
ed reference to `__glewUseProgram'
C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x14e): undefin
ed reference to `__glewVertexAttribPointer'
C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x187): undefin
ed reference to `__glewEnableVertexAttribArray'
C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x1c0): undefin
ed reference to `__glewBindVertexArray'
C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x227): undefin
ed reference to `glutInitDisplayMode'
C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x23b): undefin
ed reference to `glutInitWindowSize'
C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x24f): undefin
ed reference to `glutInitContextVersion'
C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x25b): undefin
ed reference to `glutInitContextProfile'
C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x26d): undefin
ed reference to `glewInit@0'
C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x2b8): undefin
ed reference to `glutDisplayFunc'
C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x2bd): undefin
ed reference to `glutMainLoop'
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: C:\Users\A
lex\AppData\Local\Temp\ccbYi3fS.o: bad reloc address 0x0 in section `.ctors'
collect2.exe: error: ld returned 1 exit status
Makefile:26: recipe for target 'all' failed
mingw32-make: *** [all] Error 1
Could someone please help me run an OpenGL program using MinGW or show me an alternative source for learning OpenGL under Windows with MinGW that doesn’t employ the deprecated pipeline?