From 8c02c0636e8cff892651150b90087a2bba245aba Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 11 Oct 2015 16:41:00 -0400 Subject: [PATCH] build with GL3W --- Makefile | 22 ++++++++++++++++------ app.cc | 40 ++++++++++++++++++---------------------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 70b366b..753412f 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,32 @@ -FILE := app -TARGET := $(FILE) +TARGET := app +OBJS := app.o GL3/gl3w.o REPOS := glcxx glm CCFLAGS := $(shell sdl2-config --cflags) ifeq (MINGW,$(findstring MINGW,$(shell uname))) -LIBS := -lopengl32 -lglu32 -lmingw32 +LIBS := -lopengl32 -lmingw32 CXX := mingw32-g++ TARGET := $(TARGET).exe else -LIBS := -lGL -lGLU `sdl2-config --libs` +LIBS := -lGL `sdl2-config --libs` endif +LIBS += -ldl LDFLAGS := $(LIBS) $(shell sdl2-config --libs) +CCFLAGS += -I glcxx/include -I glm -I. +CXXFLAGS += -std=gnu++14 +CCFLAGS += -DGLCXX_GL_INCLUDE='"GL3/gl3w.h"' all: submodule_init $(TARGET) -$(TARGET): $(FILE).cc - $(CXX) -o $(TARGET) $(CCFLAGS) $< $(LDFLAGS) +$(TARGET): $(OBJS) + $(CXX) -o $(TARGET) $^ $(LDFLAGS) + +%.o: %.c + $(CC) -c -o $@ $(CCFLAGS) $(CFLAGS) $< + +%.o: %.cc + $(CXX) -c -o $@ $(CCFLAGS) $(CXXFLAGS) $< .PHONY: submodule_init submodule_init: diff --git a/app.cc b/app.cc index 00d1d46..376c25a 100644 --- a/app.cc +++ b/app.cc @@ -1,7 +1,12 @@ #include -#include -#include #include +#include "glcxx.hpp" +#include "GL3/gl3w.h" +#include + +using namespace std; + +std::shared_ptr program; #define WIDTH 800 #define HEIGHT 800 @@ -10,32 +15,12 @@ void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glEnable(GL_DEPTH_TEST); - glShadeModel(GL_FLAT); glViewport(0, 0, WIDTH, HEIGHT); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(-0.5, WIDTH - 0.5, -0.5, HEIGHT - 0.5, -1, 1); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); } void display(SDL_Window * window) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glColor3f(1, 1, 1); - glBegin(GL_QUADS); - glVertex3f(10, HEIGHT / 2, 0.0); - glVertex3f(10, 3 * HEIGHT / 4, 0.0); - glVertex3f(WIDTH / 2, 3 * HEIGHT / 4, 0.0); - glVertex3f(WIDTH / 2, HEIGHT / 2, 0.0); - glEnd(); - glColor3f(1, 0.6, 0); - glBegin(GL_LINE_LOOP); - glVertex2f(0, 0); - glVertex2f(WIDTH - 1, 0); - glVertex2f(WIDTH - 1, HEIGHT - 1); - glVertex2f(0, HEIGHT - 1); - glEnd(); SDL_GL_SwapWindow(window); } @@ -64,6 +49,17 @@ int main(int argc, char *argv[]) SDL_GLContext gl_context = SDL_GL_CreateContext(window); + if (gl3wInit()) + { + cerr << "Failed to initialize GL3W" << endl; + return 2; + } + if (!gl3wIsSupported(3, 0)) + { + cerr << "OpenGL 3.0 is not supported!" << endl; + return 2; + } + init(); display(window); SDL_Event event;