Skip to content

Commit 2cf80f5

Browse files
committed
fixed the cube draw thing
1 parent d45d150 commit 2cf80f5

File tree

6 files changed

+39
-21
lines changed

6 files changed

+39
-21
lines changed

Cube.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Cube::~Cube(){
5050

5151
void Cube::draw(glm::mat4 C){
5252

53-
// this->toWorld = C;
53+
this->toWorld = C;
5454

5555
//Draw
5656
glm::mat4 modelview = Window::V * toWorld;

Window.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ glm::vec3 cam_up(0.0f, 1.0f, 0.0f); // up | What orientation "up" is
1515
GLint shaderProgram;
1616
GLint skyShaderProgram;
1717
GLint waterProgram;
18-
GLint terrainProgram;
18+
GLint cubeProgram;
1919
GLint particleProgram;
2020
GLint fullScreenShader;
2121
GLuint clipPlaneW, clipPlaneN;
@@ -35,8 +35,8 @@ int rightMouseDown;
3535
#define SKYBOX_F_SHADER_PATH "../skyboxShader.frag"
3636
#define W_V_SHADER_PATH "../waterShader.vert"
3737
#define W_F_SHADER_PATH "../waterShader.frag"
38-
#define T_V_SHADER_PATH "../terrain.vert"
39-
#define T_F_SHADER_PATH "../terrain.frag"
38+
#define C_V_SHADER_PATH "../cube.vert"
39+
#define C_F_SHADER_PATH "../cube.frag"
4040
#define P_SHADER_V "../particleShader.vert"
4141
#define P_SHADER_F "../particleShader.frag"
4242
#define FS_SHADER_V "../fullScreenShader.vert"
@@ -112,7 +112,7 @@ GLuint loc_reflection, loc_refraction, loc_dudv, loc_move_factor, loc_cam_pos, l
112112
GLuint dudvTex, normalTex;
113113
//Post processing locations
114114
GLuint loc_gauss, loc_neon;
115-
bool gauss_on = false, neon_on = false;
115+
bool gauss_on = false, neon_on = false, show_cubes = false;
116116

117117
//Time
118118
clock_t timer;
@@ -137,7 +137,7 @@ void Window::initialize_objects()
137137
shaderProgram = LoadShaders(V_SHADER_PATH, F_SHADER_PATH);
138138
skyShaderProgram = LoadShaders(SKYBOX_V_SHADER_PATH, SKYBOX_F_SHADER_PATH);
139139
waterProgram = LoadShaders(W_V_SHADER_PATH, W_F_SHADER_PATH);
140-
terrainProgram = LoadShaders(T_V_SHADER_PATH, T_F_SHADER_PATH);
140+
cubeProgram = LoadShaders(C_V_SHADER_PATH, C_F_SHADER_PATH);
141141
particleProgram = LoadShaders(P_SHADER_V, P_SHADER_F);
142142
fullScreenShader = LoadShaders(FS_SHADER_V, FS_SHADER_F);
143143

@@ -173,7 +173,7 @@ void Window::initialize_objects()
173173
engine->play2D(RAIN_1, true);
174174

175175
skybox = new SkyBox();
176-
cube = new Cube(shaderProgram);
176+
cube = new Cube(cubeProgram);
177177

178178

179179
hm = new Terrain(shaderProgram, SIMPLE_HEIGHT_MAP, 10);
@@ -260,7 +260,7 @@ void Window::clean_up()
260260
glDeleteProgram(shaderProgram);
261261
glDeleteProgram(skyShaderProgram);
262262
glDeleteProgram(waterProgram); // no more drinkable water in LA
263-
glDeleteProgram(terrainProgram);
263+
glDeleteProgram(cubeProgram);
264264
}
265265

266266
GLFWwindow* Window::create_window(int width, int height)
@@ -425,9 +425,21 @@ void Window::drawObjects(){
425425
hm->draw(hm_mat);
426426
// glBindVertexArray(0);
427427
// glBindTexture(GL_TEXTURE_2D, 0);
428-
429-
glUniform1i(glGetUniformLocation(shaderProgram, "texturize"), false);
430-
cube->draw(glm::mat4(1.0f));
428+
glUseProgram(cubeProgram);
429+
if (show_cubes){
430+
glUniform1i(glGetUniformLocation(cubeProgram, "cube_color"), 1);
431+
glm::mat4 cb_mat = glm::translate(glm::mat4(1.0f), glm::vec3(0, 10.0, 0));
432+
cube->draw(cb_mat);
433+
434+
glUniform1i(glGetUniformLocation(cubeProgram, "cube_color"), 2);
435+
glm::mat4 cb1_mat = glm::translate(glm::mat4(1.0f), glm::vec3(10.0, 20.0, 0));
436+
cube->draw(cb1_mat);
437+
438+
glUniform1i(glGetUniformLocation(cubeProgram, "cube_color"), 3);
439+
glm::mat4 cb2_mat = glm::translate(glm::mat4(1.0f), glm::vec3(-10.0, 30.0, 0));
440+
cube->draw(cb2_mat);
441+
}
442+
glUseProgram(shaderProgram);
431443
}
432444
void Window::drawReflection(){
433445
//Render everything above water (reflection)
@@ -676,6 +688,10 @@ void Window::key_callback(GLFWwindow* window, int key, int scancode, int action,
676688
// }
677689
//
678690
//>>>>>>> 14ad8e24514fc53849d8b10095427afa12500312
691+
692+
if (key == GLFW_KEY_C){
693+
show_cubes = !show_cubes;
694+
}
679695
}
680696
}
681697

terrain.frag renamed to cube.frag

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ uniform sampler2D fieldsTex;
1111

1212
uniform bool wire;
1313
uniform bool water;
14+
uniform int cube_color;
1415

1516
void main()
1617
{
1718
// Color everything a hot blue color. An alpha of 1.0f means it is not transparent.
18-
// color = vec4(1.0f, 0.0f, 1.0f, 1.0f);
19-
vec3 norm = normalize(Normal);
20-
vec3 viewDir = normalize(viewPos - FragPos);
21-
if(wire)
22-
color = vec4(0.0f, .5f, .5f, 1.0f);
23-
else
24-
color = vec4(.87f, .3f, 0.0f, 1.0f);
19+
if (cube_color == 1){
20+
color = vec4(1.0, 0.0, 0.0, 1.0);
21+
} else if (cube_color == 2){
22+
color = vec4(0.0, 0.0, 1.0, 1.0);
23+
} else if (cube_color == 3){
24+
color = vec4(0.0, 1.0, 0.0, 1.0);
25+
}
2526

26-
// color = texture(grassTex, TexCoords);
2727
}

terrain.vert renamed to cube.vert

File renamed without changes.

main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ void setup_callbacks()
3232
glfwSetErrorCallback(error_callback);
3333
// Set the key callback
3434
glfwSetKeyCallback(window, Window::key_callback);
35-
// Set the window resize callback
36-
glfwSetFramebufferSizeCallback(window, Window::resize_callback);
3735
// Set the scroll callback
3836
glfwSetScrollCallback(window, Window::scroll_callback);
3937
// Set the mouse callback
4038
glfwSetMouseButtonCallback(window, Window::mouse_button_callback);
4139
// Set the cursor position callback
4240
glfwSetCursorPosCallback(window, Window::mouse_move_callback);
41+
// Set the window resize callback
42+
glfwSetFramebufferSizeCallback(window, Window::resize_callback);
4343

4444

4545
}

shader.frag

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ void main()
121121
else
122122
color = vec4(127.0f/255.0f, 66.0f/255.0f, 50.0f/255.0f, 1.0f);
123123
}
124+
125+
124126
//
125127

126128
// if (texturize){

0 commit comments

Comments
 (0)