Changeset dba67b2 in opengl-game


Ignore:
Timestamp:
Jun 27, 2018, 1:53:47 AM (6 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
3d06b4e
Parents:
5527206
Message:

Update the project to GLM 0.9.9, add the README to the Visual Studio project, and update the Windows build instructions in the README.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • NewOpenGLGame.vcxproj

    r5527206 rdba67b2  
    157157    <Text Include="gl.log" />
    158158    <Text Include="opengl-notes.txt" />
     159    <Text Include="README.txt" />
    159160    <Text Include="TODO.txt" />
    160161  </ItemGroup>
  • README.txt

    r5527206 rdba67b2  
    3131
    3232Download the precompiled 32bit binaries of GLFW and GLEW. Create lib/ and
    33 include/ folders in the root opengl-game directory you cloned. Copy the include/GL/ and include/GLFW/ folders into your include/ folder and all the files in
    34 the lib/ folders of the GLFW and GLEW libraries into your lib/ folder. Also
    35 copy the .dll files into the root opengl-game directory. This should be enough
    36 to compile and run the project.
     33include/ folders in the root opengl-game directory you cloned.
     34Copy the include/GL/ and include/GLFW/ folders into your include/ folder.
    3735
    38 I would like to figure out how to statically compile glew and glfw to eliminate the need for the dlls.
     36For GLEW, copy lib/RELEASE/Win32/glew32s.lib into your lib folder.
     37For GLFW, copy lib-vc2015/glfw3.lib into your lib folder.
     38
     39Download GLM and copy the glm folder (the one with all the .hpp files) into the include/ folder you made above.
     40GLM is a header-only library, so there is nothing to copy into the lib/ folder.
     41
     42Open and run NewOpenGLGame.sln in Visual Studio 2017 and run it.
  • new-game.cpp

    r5527206 rdba67b2  
    88
    99#define _USE_MATH_DEFINES
    10 #define GLM_SWIZZLE
    11 
    12 // This is to fix a non-alignment issue when passing vec4 params.
    13 // Check if it got fixed in a later version of GLM
    14 #define GLM_FORCE_PURE
    1510
    1611#include <glm/mat4x4.hpp>
     
    378373   };
    379374
    380    T_model = translate(mat4(), vec3(0.45f, -1.5f, 0.0f));
    381    R_model = rotate(mat4(), 0.0f, vec3(0.0f, 1.0f, 0.0f));
     375   T_model = translate(mat4(1.0f), vec3(0.45f, -1.5f, 0.0f));
     376   R_model = rotate(mat4(1.0f), 0.0f, vec3(0.0f, 1.0f, 0.0f));
    382377   obj.model_base = T_model*R_model;
    383378
     
    413408   };
    414409
    415    T_model = translate(mat4(), vec3(-0.5f, -1.5f, -1.00f));
    416    R_model = rotate(mat4(), 0.5f, vec3(0.0f, 1.0f, 0.0f));
     410   T_model = translate(mat4(1.0f), vec3(-0.5f, -1.5f, -1.00f));
     411   R_model = rotate(mat4(1.0f), 0.5f, vec3(0.0f, 1.0f, 0.0f));
    417412   obj.model_base = T_model*R_model;
    418413
     
    791786   obj.selected_colors = { 0.0f };
    792787
    793    T_model = translate(mat4(), vec3(0.0f, -1.2f, 1.8f));
    794    R_model = rotate(mat4(), 20.0f * (float)ONE_DEG_IN_RAD, vec3(1.0f, 0.0f, 0.0f));
    795    R_model = mat4();
    796    obj.model_base = T_model * R_model * scale(mat4(), vec3(0.1f, 0.1f, 0.1f));
     788   T_model = translate(mat4(1.0f), vec3(0.0f, -1.2f, 1.8f));
     789   R_model = rotate(mat4(1.0f), 20.0f * (float)ONE_DEG_IN_RAD, vec3(1.0f, 0.0f, 0.0f));
     790   R_model = mat4(1.0f);
     791   obj.model_base = T_model * R_model * scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f));
    797792
    798793   addObjectToSceneDuringInit(obj);
     
    921916   float cam_pitch = -50.0f * 2.0f * 3.14159f / 360.0f;
    922917
    923    mat4 T = translate(mat4(), vec3(-cam_pos.x, -cam_pos.y, -cam_pos.z));
    924    mat4 yaw_mat = rotate(mat4(), -cam_yaw, vec3(0.0f, 1.0f, 0.0f));
    925    mat4 pitch_mat = rotate(mat4(), -cam_pitch, vec3(1.0f, 0.0f, 0.0f));
     918   mat4 T = translate(mat4(1.0f), vec3(-cam_pos.x, -cam_pos.y, -cam_pos.z));
     919   mat4 yaw_mat = rotate(mat4(1.0f), -cam_yaw, vec3(0.0f, 1.0f, 0.0f));
     920   mat4 pitch_mat = rotate(mat4(1.0f), -cam_pitch, vec3(1.0f, 0.0f, 0.0f));
    926921   mat4 R = pitch_mat * yaw_mat;
    927922   view_mat = R*T;
     
    10561051         /*
    10571052         if (key_state[GLFW_KEY_SPACE] == GLFW_PRESS) {
    1058             transformObject(objects[1], translate(mat4(), vec3(0.3f, 0.0f, 0.0f)), ubo);
     1053            transformObject(objects[1], translate(mat4(1.0f), vec3(0.3f, 0.0f, 0.0f)), ubo);
    10591054         }
    10601055         if (key_pressed[GLFW_KEY_RIGHT]) {
    1061             transformObject(objects[2], translate(mat4(), vec3(0.01f, 0.0f, 0.0f)), ubo);
     1056            transformObject(objects[2], translate(mat4(1.0f), vec3(0.01f, 0.0f, 0.0f)), ubo);
    10621057         }
    10631058         if (key_pressed[GLFW_KEY_LEFT]) {
    1064             transformObject(objects[2], translate(mat4(), vec3(-0.01f, 0.0f, 0.0f)), ubo);
     1059            transformObject(objects[2], translate(mat4(1.0f), vec3(-0.01f, 0.0f, 0.0f)), ubo);
    10651060         }
    10661061         */
    10671062
    10681063         if (key_pressed[GLFW_KEY_RIGHT]) {
    1069             transformObject(objects[0], translate(mat4(), vec3(0.01f, 0.0f, 0.0f)), ubo);
     1064            transformObject(objects[0], translate(mat4(1.0f), vec3(0.01f, 0.0f, 0.0f)), ubo);
    10701065         }
    10711066         if (key_pressed[GLFW_KEY_LEFT]) {
    1072             transformObject(objects[0], translate(mat4(), vec3(-0.01f, 0.0f, 0.0f)), ubo);
     1067            transformObject(objects[0], translate(mat4(1.0f), vec3(-0.01f, 0.0f, 0.0f)), ubo);
    10731068         }
    10741069
    10751070         for (int i = 1; i < objects.size(); i++) {
    10761071            if (!objects[i].deleted) {
    1077                transformObject(objects[i], translate(mat4(), vec3(0.0f, 0.0f, 0.04f)), ubo);
     1072               transformObject(objects[i], translate(mat4(1.0f), vec3(0.0f, 0.0f, 0.04f)), ubo);
    10781073            }
    10791074         }
     
    10901085      float dist = cam_speed * elapsed_seconds;
    10911086      if (key_pressed[GLFW_KEY_A]) {
    1092          vec3 dir = (inverse(R) * vec4(-1.0f, 0.0f, 0.0f, 1.0f)).xyz();
     1087         vec3 dir = vec3(inverse(R) * vec4(-1.0f, 0.0f, 0.0f, 1.0f));
    10931088         cam_pos += dir * dist;
    10941089
     
    10961091      }
    10971092      if (key_pressed[GLFW_KEY_D]) {
    1098          vec3 dir = (inverse(R) * vec4(1.0f, 0.0f, 0.0f, 1.0f)).xyz();
     1093         vec3 dir = vec3(inverse(R) * vec4(1.0f, 0.0f, 0.0f, 1.0f));
    10991094         cam_pos += dir * dist;
    11001095
     
    11021097      }
    11031098      if (key_pressed[GLFW_KEY_W]) {
    1104          vec3 dir = (inverse(R) * vec4(0.0f, 0.0f, -1.0f, 1.0f)).xyz();
     1099         vec3 dir = vec3(inverse(R) * vec4(0.0f, 0.0f, -1.0f, 1.0f));
    11051100         cam_pos += dir * dist;
    11061101
     
    11081103      }
    11091104      if (key_pressed[GLFW_KEY_S]) {
    1110          vec3 dir = (inverse(R) * vec4(0.0f, 0.0f, 1.0f, 1.0f)).xyz();
     1105         vec3 dir = vec3(inverse(R) * vec4(0.0f, 0.0f, 1.0f, 1.0f));
    11111106         cam_pos += dir * dist;
    11121107
     
    11321127      */
    11331128      if (cam_moved) {
    1134          T = translate(mat4(), vec3(-cam_pos.x, -cam_pos.y, -cam_pos.z));
    1135 
    1136          mat4 yaw_mat = rotate(mat4(), -cam_yaw, vec3(0.0f, 1.0f, 0.0f));
    1137          mat4 pitch_mat = rotate(mat4(), -cam_pitch, vec3(1.0f, 0.0f, 0.0f));
     1129         T = translate(mat4(1.0f), vec3(-cam_pos.x, -cam_pos.y, -cam_pos.z));
     1130
     1131         mat4 yaw_mat = rotate(mat4(1.0f), -cam_yaw, vec3(0.0f, 1.0f, 0.0f));
     1132         mat4 pitch_mat = rotate(mat4(1.0f), -cam_pitch, vec3(1.0f, 0.0f, 0.0f));
    11381133         R = pitch_mat * yaw_mat;
    11391134
     
    12031198      vec4 ray_clip = vec4(x, y, -1.0f, 1.0f);
    12041199      vec4 ray_eye = inverse(proj_mat) * ray_clip;
    1205       ray_eye = vec4(ray_eye.xy(), -1.0f, 1.0f);
     1200      ray_eye = vec4(vec2(ray_eye), -1.0f, 1.0f);
    12061201      vec4 ray_world = inverse(view_mat) * ray_eye;
    12071202
     
    12251220
    12261221               if (-NEAR_CLIP >= click_point.z && click_point.z > -FAR_CLIP && click_point.z > closest_point.z) {
    1227                   closest_point = click_point.xyz();
     1222                  closest_point = vec3(click_point);
    12281223                  closest_object = &*it;
    12291224               }
     
    13401335   vec3 normal = vec3(v1.y*v2.z - v1.z*v2.y, v1.z*v2.x - v1.x*v2.z, v1.x*v2.y - v1.y*v2.x);
    13411336
    1342    vec3 local_ray = (inverse(obj->model_mat) * world_ray).xyz();
    1343    vec3 local_cam = (inverse(obj->model_mat) * cam).xyz();
     1337   vec3 local_ray = vec3(inverse(obj->model_mat) * world_ray);
     1338   vec3 local_cam = vec3(inverse(obj->model_mat) * cam);
    13441339
    13451340   local_ray = local_ray - local_cam;
     
    13801375   obj.id = objects.size(); // currently unused
    13811376   obj.num_points = obj.points.size() / 3;
    1382    obj.model_transform = mat4();
     1377   obj.model_transform = mat4(1.0f);
    13831378   obj.deleted = false;
    13841379
     
    14451440      // Move the object outside the render bounds of the scene so it doesn't get rendered
    14461441      // TODO: Find a better way of hiding the object until the next time buffers are repopulated
    1447       transformObject(obj, translate(mat4(), vec3(0.0f, 0.0f, FAR_CLIP * 1000.0f)), ubo);
     1442      transformObject(obj, translate(mat4(1.0f), vec3(0.0f, 0.0f, FAR_CLIP * 1000.0f)), ubo);
    14481443      obj.deleted = true;
    14491444   }
     
    18801875   obj.selected_colors = { 0.0f };
    18811876
    1882    mat4 T = translate(mat4(), pos);
    1883    mat4 R = rotate(mat4(), 60.0f * (float)ONE_DEG_IN_RAD, vec3(1.0f, 1.0f, -1.0f));
    1884    obj.model_base = T * R * scale(mat4(), vec3(0.1f, 0.1f, 0.1f));
     1877   mat4 T = translate(mat4(1.0f), pos);
     1878   mat4 R = rotate(mat4(1.0f), 60.0f * (float)ONE_DEG_IN_RAD, vec3(1.0f, 1.0f, -1.0f));
     1879   obj.model_base = T * R * scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f));
    18851880
    18861881   addObjectToScene(obj, shaderBufferInfo,
Note: See TracChangeset for help on using the changeset viewer.