Getting Started

So, I documented my self, I instaled it to codeblocks, it work.

Here is what I want to get knowing:

  1. When I first created the window it crashed it.
    2)I did vectors at school, and I know math, my problem is I don’t know the terms in english, but I learn fast.
    3)How I can make a fps camera???
    4)How I can draw a cube? At a x, y, z?

I forgot to mention I work on c++ and I know, the basics, and object oriented

Where did it crash? Run your program under debugger and examine call stack to see the location and from where it was called. Usually this happens because you pass wrong values to some functions, so examine local variables to figure out what values you have used.

3 and 4 are really not GLFW questions. GLFW only opens window and provides you input events. Everything else (camera, drawing, etc…) you do thorugh OpenGL or Vulkan. I suggest you visit https://www.khronos.org/opengl/wiki/ to learn more about OpenGL.

1 Like

Q: Are you still having problems with the window crashing?

OpenGL has many different levels of API. If you want to study ‘modern’ OpenGL with shaders then I would look for tutorials for OpenGL 3 or OpenGL 4.

I found what seems to be a decent tutorial for OpenGL 4 here: http://antongerdelan.net/opengl/, the basics are available there for free with a fair priced eBook download for the rest of the tutorials and code on Github https://github.com/capnramses/antons_opengl_tutorials_book

#include <iostream>
#include <GLFW/glfw3.h>

using namespace std;

int main(void)
{
    if(!glfwInit())
    {
        //glfwTerminate();
        cout << "Failed to launch";
        return -1;
    }

    GLFWwindow* window = glfwCreateWindow(640, 480, "Minecraft", NULL, NULL);

    if(!window)
        glfwTerminate();

    glfwMakeContextCurrent(window);

    while(!glfwWindowShouldClose(window))
    {
        glfwSwapBuffers(window);
        glfwPollEvents();// if this line is missing it crash
    }

    glfwTerminate();
}

Tell me if is missing something? About cube I know how to make it from 3d vertex, and rotate it with cos and sin.

A couple of code review points:

cout << "Failed to launch";

Errors should probably be sent to cerr rather than cout. You should also send a endl after your message to flush the buffer, otherwise it will not be printed immediately (or at all).

if(!window)
    glfwTerminate();

You should also end your program in this circumstance, otherwise your code continues to try and use the null pointer in the following lines.

glfwPollEvents();// if this line is missing it crash

You need to call either glfwPollEvents() or glfwWaitEvents() regularly to receive important messages from the operating system. It is less than ideal, but I am not surprised that the program crashes without that line.

I recommend setting an error callback to notify you if/when errors are generated within GLFW. See http://www.glfw.org/docs/latest/group__init.html#gaa5d796c3cf7c1a7f02f845486333fb5f for information.

Your other questions are quite complex, and will require OpenGL knowledge. I suggest finding a tutorial and starting there before trying to do everything from scratch.

It’s all I got, but here’s my old minimal example of a single-threaded 3D ‘game’. It uses OpenGL 1(!) and GLFW2 (a couple changes required) to draw lines, react to input, move a camera, and block the main loop between frames.