Changeset e856d62 in opengl-game
- Timestamp:
- Apr 3, 2018, 3:11:47 AM (7 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 046ce72
- Parents:
- 267c4c5
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
NewOpenGLGame.vcxproj
r267c4c5 re856d62 135 135 <ItemGroup> 136 136 <Text Include="gl.log" /> 137 <Text Include="TODO.txt" /> 137 138 </ItemGroup> 138 139 <ItemGroup> -
new-game.cpp
r267c4c5 re856d62 147 147 148 148 GLFWwindow* window = NULL; 149 GLFWmonitor* mon = NULL; 149 150 150 151 if (FULLSCREEN) { 151 GLFWmonitor*mon = glfwGetPrimaryMonitor();152 mon = glfwGetPrimaryMonitor(); 152 153 const GLFWvidmode* vmode = glfwGetVideoMode(mon); 153 154 cout << "Fullscreen resolution " << vmode->width << "x" << vmode->height << endl;155 window = glfwCreateWindow(vmode->width, vmode->height, "Extended GL Init", mon, NULL);156 154 157 155 width = vmode->width; 158 156 height = vmode->height; 159 } else { 160 window = glfwCreateWindow(width, height, "Hello Triangle", NULL, NULL); 157 cout << "Fullscreen resolution " << vmode->width << "x" << vmode->height << endl; 161 158 } 159 window = glfwCreateWindow(width, height, "New OpenGL Game", mon, NULL); 162 160 163 161 if (!window) { … … 172 170 glewExperimental = GL_TRUE; 173 171 glewInit(); 174 175 // Check the extended initialization section of the book to learn how to use this176 // Maybe move this and other OpenGL setup/settings code into a separate function177 // glViewport(0, 0, width*2, height*2);178 172 179 173 const GLubyte* renderer = glGetString(GL_RENDERER); … … 195 189 cout << x << endl; 196 190 cout << y << endl; 197 printf 191 printf("first 4 bytes are: %i %i %i %i\n", texImage[0], texImage[1], texImage[2], texImage[3]); 198 192 } 199 193 … … 560 554 cout << "Loaded successfully" << endl; 561 555 } else { 562 cout << "Failed to load ethe file" << endl;556 cout << "Failed to load the file" << endl; 563 557 } 564 558 … … 581 575 unsigned char* loadImage(string file_name, int* x, int* y) { 582 576 int n; 583 int force_channels = 4; 577 int force_channels = 4; // This forces RGBA (4 bytes per pixel) 584 578 unsigned char* image_data = stbi_load(file_name.c_str(), x, y, &n, force_channels); 579 580 int width_in_bytes = *x * 4; 581 unsigned char *top = NULL; 582 unsigned char *bottom = NULL; 583 unsigned char temp = 0; 584 int half_height = *y / 2; 585 586 // flip image upside-down to account for OpenGL treating lower-left as (0, 0) 587 for (int row = 0; row < half_height; row++) { 588 top = image_data + row * width_in_bytes; 589 bottom = image_data + (*y - row - 1) * width_in_bytes; 590 for (int col = 0; col < width_in_bytes; col++) { 591 temp = *top; 592 *top = *bottom; 593 *bottom = temp; 594 top++; 595 bottom++; 596 } 597 } 598 585 599 if (!image_data) { 586 600 fprintf(stderr, "ERROR: could not load %s\n", file_name.c_str()); 587 601 } 602 603 // Not Power-of-2 check 604 if ((*x & (*x - 1)) != 0 || (*y & (*y - 1)) != 0) { 605 fprintf(stderr, "WARNING: texture %s is not power-of-2 dimensions\n", file_name.c_str()); 606 } 607 588 608 return image_data; 589 609 }
Note:
See TracChangeset
for help on using the changeset viewer.