test opty

Members
  • Content count

    22
  • Joined

  • Last visited

Community Reputation

0 Neutral

1 Follower

About test opty

  • Rank
    Member

Personal Information

  • Interests
    Programming
  1. Hi, another question: This function: void framebuffer_size_callback(GLFWwindow* window, int width, int height) { glViewport(0, 0, width, height); } is called by this statement: glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); Here the parameters width and height aren't set, so how does the function above set its arguments to be used by glViewport?
  2. Thank you very much. I appreciate all your help.
  3. Thank you. I got many things from your answer. There was some misunderstanding, but it got solved now. The picture seems very meaningful but I can't read the text. Where can I find it's large size to read them please?
  4. I got all the other stuff except this part. First off, thanks. Well, each frame is our resulting window and presumably every iteration copies the same frame as the prior one on the window! That is, coping equal frames onto each other! It does so because using the loop we tell it so. It's an infinite loop and if I don't close the window it should run forever! OK. But why 97 times or 137 or so while I haven't close the window, please?
  5. Yes, it solved the issue and demonstrated that one frame is enough for that result. Thanks. But would you please answer other questions I ask above too.
  6. I'm at the beginning of learning OpenGL, so it's not a game I think. By the way, does this convey that OpenGL is mostly for developing games? I used the statements without the loop (removed the loop) but the resulting window is shown and immediately vanishing! I even can't see it! I think the loop is also for keeping the output (window) so that we are able to see the result. As an another attempt to figure the issue out completely, I reused the loop and put a counter into it. Now I can see the resulting window. Then I couted that counter (I use C++). It showed different values, say, from 75, 97 to 137 or over! That is, we have many iterations, just for a simple window! It's also strange for me.
  7. Thanks for the reply. Please have a look at the code above. It's a simple rectangle or window. So nothing is moving/animating. How many frames are needed for that (apparently) fixed picture? I guess less than 10 per second. Once again, what does each frame do in that window? If I'm frank, I think only one frame is sufficient and no frame replacing is needed.
  8. I have new questions on the case now! Here we have a simple window. It has nothing. So how many frames are needed to complete that window? If one frame is to draw, say, a corner of the window, why do we need to replace it with a new one in the next frame?!
  9. OpenGL The simplest OpenGL example

    Sorry but these are not what I need! The window I'm talking about should presumably have only few lines of code. We want a simple, say, 800x600, window with a title like "First Window". That's all.
  10. Hi all, I'm starting OpenGL using a tut on the Web. But at this point I would like to know the primitives needed for creating a window using OpenGL. So on Windows and using MS VS 2017, what is the simplest code required to render a window with the title of "First Rectangle", please?
  11. Thanks for the reply. Yeah, it seems that way but honestly complicated for a starter. I guess this part (that is, most of my code), is just like framework for the rest of the programs. That is, we supply that code as a base and after that our hands are free to by code to tell the compiler what we want, in programs. What lines did you exactly mean please? Yes, I accept. What at this point I need is that, what stages do we need to code for making such a triangle in OpenGL? For example, how many steps/stages are needed to create such a triangle specifically or other OpenGL programs generally? (If we can divide the code into stages) and what lines in that code do belong to each stage please?
  12. Hi, I'm trying to learn OpenGL through a website and have proceeded until this page of it. The output is a simple triangle. The problem is the complexity. I have read that page several times and tried to analyse the code but I haven't understood the code properly and completely yet. This is the code: #include <glad/glad.h> #include <GLFW/glfw3.h> #include <C:\Users\Abbasi\Desktop\std_lib_facilities_4.h> using namespace std; //****************************************************************************** void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); // settings const unsigned int SCR_WIDTH = 800; const unsigned int SCR_HEIGHT = 600; const char *vertexShaderSource = "#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" "void main()\n" "{\n" " gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n" "}\0"; const char *fragmentShaderSource = "#version 330 core\n" "out vec4 FragColor;\n" "void main()\n" "{\n" " FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n" "}\n\0"; //******************************* int main() { // glfw: initialize and configure // ------------------------------ glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // glfw window creation GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "My First Triangle", nullptr, nullptr); if (window == nullptr) { cout << "Failed to create GLFW window" << endl; glfwTerminate(); return -1; } glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); // glad: load all OpenGL function pointers if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { cout << "Failed to initialize GLAD" << endl; return -1; } // build and compile our shader program // vertex shader int vertexShader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vertexShader, 1, &vertexShaderSource, nullptr); glCompileShader(vertexShader); // check for shader compile errors int success; char infoLog[512]; glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success); if (!success) { glGetShaderInfoLog(vertexShader, 512, nullptr, infoLog); cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << endl; } // fragment shader int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fragmentShader, 1, &fragmentShaderSource, nullptr); glCompileShader(fragmentShader); // check for shader compile errors glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success); if (!success) { glGetShaderInfoLog(fragmentShader, 512, nullptr, infoLog); cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << endl; } // link shaders int shaderProgram = glCreateProgram(); glAttachShader(shaderProgram, vertexShader); glAttachShader(shaderProgram, fragmentShader); glLinkProgram(shaderProgram); // check for linking errors glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success); if (!success) { glGetProgramInfoLog(shaderProgram, 512, nullptr, infoLog); cout << "ERROR::SHADER::PROGRAM::LINKING_FAILED\n" << infoLog << endl; } glDeleteShader(vertexShader); glDeleteShader(fragmentShader); // set up vertex data (and buffer(s)) and configure vertex attributes float vertices[] = { -0.5f, -0.5f, 0.0f, // left 0.5f, -0.5f, 0.0f, // right 0.0f, 0.5f, 0.0f // top }; unsigned int VBO, VAO; glGenVertexArrays(1, &VAO); glGenBuffers(1, &VBO); // bind the Vertex Array Object first, then bind and set vertex buffer(s), //and then configure vertex attributes(s). glBindVertexArray(VAO); glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); glEnableVertexAttribArray(0); // note that this is allowed, the call to glVertexAttribPointer registered VBO // as the vertex attribute's bound vertex buffer object so afterwards we can safely unbind glBindBuffer(GL_ARRAY_BUFFER, 0); // You can unbind the VAO afterwards so other VAO calls won't accidentally // modify this VAO, but this rarely happens. Modifying other // VAOs requires a call to glBindVertexArray anyways so we generally don't unbind // VAOs (nor VBOs) when it's not directly necessary. glBindVertexArray(0); // uncomment this call to draw in wireframe polygons. //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // render loop while (!glfwWindowShouldClose(window)) { // input // ----- processInput(window); // render // ------ glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); // draw our first triangle glUseProgram(shaderProgram); glBindVertexArray(VAO); // seeing as we only have a single VAO there's no need to // bind it every time, but we'll do so to keep things a bit more organized glDrawArrays(GL_TRIANGLES, 0, 3); // glBindVertexArray(0); // no need to unbind it every time // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.) glfwSwapBuffers(window); glfwPollEvents(); } // optional: de-allocate all resources once they've outlived their purpose: glDeleteVertexArrays(1, &VAO); glDeleteBuffers(1, &VBO); // glfw: terminate, clearing all previously allocated GLFW resources. glfwTerminate(); return 0; } //************************************************** // process all input: query GLFW whether relevant keys are pressed/released // this frame and react accordingly void processInput(GLFWwindow *window) { if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); } //******************************************************************** // glfw: whenever the window size changed (by OS or user resize) this callback function executes void framebuffer_size_callback(GLFWwindow* window, int width, int height) { // make sure the viewport matches the new window dimensions; note that width and // height will be significantly larger than specified on retina displays. glViewport(0, 0, width, height); } As you see, about 200 lines of complicated code only for a simple triangle. I don't know what parts are necessary for that output. And also, what the correct order of instructions for such an output or programs is, generally. That start point is too complex for a beginner of OpenGL like me and I don't know how to make the issue solved. What are your ideas please? What is the way to figure both the code and the whole program out correctly please? I wish I'd read a reference that would teach me OpenGL through a step-by-step method.
  13. OpenGL My first triangle

    It only made the background window black instead of white!!
  14. OpenGL My first triangle

    Thanks, but what function did you mean please? There are many functions in the code.