saved window position on startup.
tidy up moar. exercises.
This commit is contained in:
parent
1a96538a0e
commit
437b1ccd44
6 changed files with 74 additions and 31 deletions
70
mybox.cpp
70
mybox.cpp
|
@ -24,6 +24,8 @@ int main(void) {
|
|||
// Build the winodw
|
||||
GLFWwindow *window = glfwCreateWindow(960, 400,
|
||||
"Hello MyBox", NULL, NULL);
|
||||
glfwSetWindowPos(window, 140, 1000);
|
||||
|
||||
if (window == NULL) {
|
||||
std::cout << "Failed to create GLFW window." << std::endl;
|
||||
glfwTerminate();
|
||||
|
@ -40,12 +42,15 @@ int main(void) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* ====================================================================== */
|
||||
/* ====================================================================== */
|
||||
/* ====================================================================== */
|
||||
i32 success;
|
||||
char infoLog[512];
|
||||
|
||||
// Create the vertex shader
|
||||
GLchar *shdr_src_vertex;
|
||||
readshader("vertex.glsl", &shdr_src_vertex);
|
||||
readshader("vertex.vert", &shdr_src_vertex);
|
||||
u32 vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertexShader, 1, &shdr_src_vertex, NULL);
|
||||
glCompileShader(vertexShader);
|
||||
|
@ -61,7 +66,7 @@ int main(void) {
|
|||
|
||||
// Create the fragment shader
|
||||
GLchar *shdr_src_fragment;
|
||||
readshader("fragment.glsl", &shdr_src_fragment);
|
||||
readshader("fragment.frag", &shdr_src_fragment);
|
||||
u32 fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragmentShader, 1, &shdr_src_fragment, NULL);
|
||||
glCompileShader(fragmentShader);
|
||||
|
@ -92,6 +97,9 @@ int main(void) {
|
|||
glDeleteShader(vertexShader);
|
||||
glDeleteShader(fragmentShader);
|
||||
|
||||
/* ====================================================================== */
|
||||
/* ====================================================================== */
|
||||
|
||||
// Define the vertex shader dat.
|
||||
f32 vertices[] = {
|
||||
0.5f, 0.5f, 0.0f, // tr
|
||||
|
@ -101,32 +109,47 @@ int main(void) {
|
|||
};
|
||||
u32 indicies[] {
|
||||
0, 1, 3, // t1
|
||||
1, 2, 3 // t2
|
||||
2, 1, 3 // t2
|
||||
};
|
||||
|
||||
u32 EBO;
|
||||
u32 VBO;
|
||||
u32 VAO;
|
||||
glGenBuffers(1, &EBO);
|
||||
glGenBuffers(1, &VBO);
|
||||
glGenVertexArrays(1, &VAO);
|
||||
u32 VBO; // Vertex Buffer Object refernce number
|
||||
glGenBuffers(1, &VBO); // ask the GPU for a reference for one buffer
|
||||
u32 VAO; // Vertex Array Object refernce number
|
||||
glGenVertexArrays(1, &VAO); // ask the GPU for a reference for one buffer
|
||||
u32 EBO; //
|
||||
glGenBuffers(1, &EBO); // ask the gpu for a reference for one buffer
|
||||
|
||||
// Bind VAO
|
||||
glBindVertexArray(VAO);
|
||||
// copy in data to the VBO
|
||||
// Bind VAO, meaning we
|
||||
glBindVertexArray(VAO);
|
||||
// Tell the GPU subsequent calls to modify buffers apply to this buffer,
|
||||
// namely, the VBO buffer.
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
// copy in data to the VBO. I.e. give it a pointer to some data, tell it
|
||||
// how the entire buffer will be. sizeof(*[]) evaluates the full allocated
|
||||
// size of the data object.
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
// Setup the indexing into the VBO data
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indicies), indicies, GL_STATIC_DRAW);
|
||||
// Next, tell the GPU how to use the GL_ELEMENT_ARRAY_BUfFER.
|
||||
// In this case, read from the 0th index, 3 elements at a time as
|
||||
// off of the indirected GL_ARRAY_BUFFER as floating point numbers. Do not
|
||||
// re-normalize the values (i.e., they're already normalized), and use a
|
||||
// stride of 3xf32 as we walk through the data in the original GL_ARRAY_BUFFER
|
||||
// Target the Atrib pointer in the VAO to the VBO inside it.
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(f32), (void *)0);
|
||||
// STart at Zero
|
||||
// For the VAO array (theoretically, but we have an array of 1), start
|
||||
// at the 0th element of the VAO array.
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
// Setup the indexing into the VBO data. The EBO is the indirection buffer
|
||||
// that tells the GPU where to look into it's known GL_ARRAY_BUFFER object
|
||||
// for data.
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indicies), indicies, GL_STATIC_DRAW);
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
// ??
|
||||
|
||||
glBindVertexArray(0); // i.e., UNBIND the vertex array.
|
||||
|
||||
|
||||
while(!glfwWindowShouldClose(window)) {
|
||||
processInput(window);
|
||||
|
||||
|
@ -136,7 +159,6 @@ int main(void) {
|
|||
|
||||
glUseProgram(shaderProgram);
|
||||
glBindVertexArray(VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||
|
||||
// Finish up
|
||||
|
@ -144,6 +166,16 @@ int main(void) {
|
|||
glfwPollEvents();
|
||||
}
|
||||
|
||||
glDeleteVertexArrays(1, &VAO);
|
||||
glDeleteBuffers(1, &VBO);
|
||||
glDeleteBuffers(1, &EBO);
|
||||
glDeleteProgram(shaderProgram);
|
||||
|
||||
i32 xpos, ypos;
|
||||
glfwGetWindowPos(window, &xpos, &ypos);
|
||||
std::cout << "Closed window at position\n (X,Y) = "
|
||||
<< xpos << ", " << ypos << "\n" << std::endl;
|
||||
|
||||
glfwTerminate();
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue