Skip to content

Commit

Permalink
Removed glu usage
Browse files Browse the repository at this point in the history
  • Loading branch information
erincatto committed Jan 13, 2019
1 parent 260f28b commit 2dc391a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ if (BOX2D_BUILD_SAMPLES)
# box2d-lite samples
add_executable(samples samples/main.cpp)
target_include_directories(samples PUBLIC imgui ${OPENGL_INCLUDE_DIR})
target_link_libraries(samples PUBLIC box2d-lite glfw imgui ${OPENGL_LIBRARIES} ${OPENGL_glu_LIBRARY})
target_link_libraries(samples PUBLIC box2d-lite glfw imgui ${OPENGL_LIBRARIES})

# default startup project for Visual Studio
if (MSVC)
Expand Down
30 changes: 25 additions & 5 deletions samples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "examples/imgui_impl_glfw.h"
#include "examples/imgui_impl_opengl2.h"

#define GLFW_INCLUDE_GLU
#include "GLFW/glfw3.h"

#include "box2d-lite/World.h"
Expand All @@ -43,6 +42,8 @@ namespace

int width = 1280;
int height = 720;
float zoom = 10.0f;
float pan_y = 8.0f;

World world(gravity, iterations);
}
Expand Down Expand Up @@ -567,7 +568,18 @@ static void Reshape(GLFWwindow*, int w, int h)
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (float)width/(float)height, 0.1, 100.0);

float aspect = float(width) / float(height);
if (width >= height)
{
// aspect >= 1, set the height from -1 to 1, with larger width
glOrtho(-zoom * aspect, zoom * aspect, -zoom + pan_y, zoom + pan_y, -1.0, 1.0);
}
else
{
// aspect < 1, set the width to -1 to 1, with larger height
glOrtho(-zoom, zoom, -zoom / aspect + pan_y, zoom / aspect + pan_y, -1.0, 1.0);
}
}

int main(int, char**)
Expand Down Expand Up @@ -609,8 +621,17 @@ int main(int, char**)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

// TODO_ERIN glOrtho
gluPerspective(45.0, (float)width / (float)height, 0.1, 100.0);
float aspect = float(width) / float(height);
if (width >= height)
{
// aspect >= 1, set the height from -1 to 1, with larger width
glOrtho(-zoom * aspect, zoom * aspect, -zoom + pan_y, zoom + pan_y, -1.0, 1.0);
}
else
{
// aspect < 1, set the width to -1 to 1, with larger height
glOrtho(-zoom, zoom, -zoom / aspect + pan_y, zoom / aspect + pan_y, -1.0, 1.0);
}

InitDemo(0);

Expand Down Expand Up @@ -642,7 +663,6 @@ int main(int, char**)

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, -7.0f, -25.0f);

world.Step(timeStep);

Expand Down

0 comments on commit 2dc391a

Please sign in to comment.