build with GL3W

This commit is contained in:
Josh Holtrop 2015-10-11 16:41:00 -04:00
parent 524b44cbcd
commit 8c02c0636e
2 changed files with 34 additions and 28 deletions

View File

@ -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:

40
app.cc
View File

@ -1,7 +1,12 @@
#include <SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <stdio.h>
#include "glcxx.hpp"
#include "GL3/gl3w.h"
#include <iostream>
using namespace std;
std::shared_ptr<glcxx::Program> 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;