I'm trying to learn OpenGL via a tutorial in youtube called Graphics Programming with OpenGL and Qt. I did everything exactly according to this tutorial but I cant render my triangle. Here is my code:
#include <GL/glew.h>
#include "GlWindow.h"
void GlWindow::initializeGL(){
glewInit();
GLfloat verts[] = {
0.0f, -1.0f,
-1.0f,-1.0f,
1.0f, -1.0f
};
GLuint myBufferID;
glGenBuffers(1, &myBufferID);
glBindBuffer(GL_ARRAY_BUFFER, myBufferID);
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0,2, GL_FLOAT, GL_FALSE, 0,0);
}
void GlWindow::paintGL(){
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 3);
}
and here is my GLWindow.h code:
#ifndef GLWINDOW_H
#define GLWINDOW_H
#include <QtOpenGL/QGLWidget>
class GlWindow : public QGLWidget{
public:
protected:
void initializeGL();
void paintGL();
};
#endif // GLWINDOW_H
And my main.cpp
#include <QApplication>
#include <GlWindow.h>
int main(int argc, char *argv[]){
QApplication app(argc, argv);
GlWindow glWindow;
glWindow.show();
return app.exec();
}
But the output is just a black window. If I also use glClearColor(1.0f,0.0f,0.0f,1.0f);
I will have a red window. But I don't know why my triangle is not shown.
Edit: Im using ubuntu 15 and when I run glx info | grep version I get this:
server glx version string: 1.4
client glx version string: 1.4
GLX version: 1.4
OpenGL core profile version string: 3.3 (Core Profile) Mesa 10.5.2
OpenGL core profile shading language version string: 3.30
OpenGL version string: 3.0 Mesa 10.5.2
OpenGL shading language version string: 1.30
OpenGL ES profile version string: OpenGL ES 3.0 Mesa 10.5.2
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00
The problem are the vertex coordinates:
GLfloat verts[] = {
0.0f, -1.0f,
-1.0f,-1.0f,
1.0f, -1.0f
Change them for example to:
GLfloat verts[] = {
0.0f, 0.0f,
0.0f,-1.0f,
-1.0f, -1.0f
and if the other code is correct you will see a triangle in the bottom left corner.
Related
I've been reading a lot about this but haven't been able to resolve anything yet. I am trying to draw a colored triangle with OpenGL3 but I get the following error:
terminate called after throwing an instance of 'std::runtime_error' what(): Compilation error for vertex shader (from file ./TP1/shaders/triangle.vs.glsl): 0:1(10): error: GLSL 3.30 is not supported. Supported versions are: 1.10, 1.20, 1.30, 1.00 ES, 3.00 ES, 3.10 ES, and 3.20 ES
When I run glxinfo | grep -i opengl I get:
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) HD Graphics 6000 (Broadwell GT3)
OpenGL core profile version string: 3.3 (Core Profile) Mesa 19.0.8
OpenGL core profile shading language version string: 4.50
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL version string: 3.0 Mesa 19.0.8
OpenGL shading language version string: 4.50
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile
OpenGL extensions:
OpenGL ES profile version string:
OpenGL ES 3.1 Mesa 19.0.8
OpenGL ES profile shading language version string:
OpenGL ES GLSL ES 3.10
OpenGL ES profile extensions:
I tried export MESA_GL_VERSION_OVERRIDE=3.3 which enables me to execute the code but I just get a weird triangle, not a nice equilateral multicolored one.
Here's my full code:
#include <glimac/SDLWindowManager.hpp>
#include <GL/glew.h>
#include <iostream>
#include <glimac/Program.hpp>
#include <glimac/FilePath.hpp>
using namespace glimac;
int main(int argc, char** argv) {
// Initialize SDL and open a window
SDLWindowManager windowManager(800, 600, "GLImac");
// Initialize glew for OpenGL3+ support
GLenum glewInitError = glewInit();
if(GLEW_OK != glewInitError) {
std::cerr << glewGetErrorString(glewInitError) << std::endl;
return EXIT_FAILURE;
}
std::cout << "OpenGL Version : " << glGetString(GL_VERSION) << std::endl;
std::cout << "GLEW Version : " << glewGetString(GLEW_VERSION) << std::endl;
//load shaders and tell OpenGL to use them
FilePath applicationPath(argv[0]);
Program program = loadProgram(applicationPath.dirPath() + "shaders/triangle.vs.glsl",
applicationPath.dirPath() + "shaders/triangle.fs.glsl");
program.use();
GLuint vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
//triangle data
GLfloat vertices[] = { -0.5f, -0.5f, 1.f, 0.f, 0.f, //2 coordinates + 1 0 0 color
0.5f, -0.5f, 0.f, 1.f, 0.f,
0.0f, 0.5f, 0.f, 0.f, 1.f };
glBufferData(GL_ARRAY_BUFFER, (15*(sizeof(float))), vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
const GLuint VERTEX_ATTR_POSITION = 3;
const GLuint VERTEX_ATTR_COLOR = 8;
glEnableVertexAttribArray(VERTEX_ATTR_POSITION);
glEnableVertexAttribArray(VERTEX_ATTR_COLOR);
const GLvoid* bouche;
glVertexAttribPointer(VERTEX_ATTR_POSITION, 2, GL_FLOAT, GL_FALSE, (0*sizeof(GL_FLOAT)), bouche);
glVertexAttribPointer(VERTEX_ATTR_COLOR, 3, GL_FLOAT, GL_FALSE, (2*sizeof(GL_FLOAT)), bouche);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer(VERTEX_ATTR_POSITION, 2, GL_FLOAT, GL_FALSE, (2*sizeof(GL_FLOAT)), 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
// Application loop:
bool done = false;
while(!done) {
// Event loop:
SDL_Event e;
while(windowManager.pollEvent(e)) {
if(e.type == SDL_QUIT) {
done = true; // Leave the loop after this iteration
}
}
//clean window
glClear(GL_COLOR_BUFFER_BIT);
glBindVertexArray(vao);
glDrawArrays(GL_TRIANGLES, 0, 3);
glBindVertexArray(0);
// Update the display
windowManager.swapBuffers();
}
//liberate allocated memory on GPU (the vbo and vao)
glDeleteBuffers(1, &vbo);
glDeleteVertexArrays(1, &vao);
return EXIT_SUCCESS;
}
When you use glew, then enable additional extensions by glewExperimental = GL_TRUE;. See the GLEW documentation which says:
GLEW obtains information on the supported extensions from the graphics driver. Experimental or pre-release drivers, however, might not report every available extension through the standard mechanism, in which case GLEW will report it unsupported. To circumvent this situation, the glewExperimental global switch can be turned on by setting it to GL_TRUE before calling glewInit(), which ensures that all extensions with valid entry points will be exposed.
glewExperimental = GL_TRUE;
GLenum glewInitError = glewInit();
if(GLEW_OK != glewInitError) {
std::cerr << glewGetErrorString(glewInitError) << std::endl;
return EXIT_FAILURE;
}
When an named buffer object is bound to the target GL_ARRAY_BUFFER, then the last parameter of glVertexAttribPointer is treated as a byte offset into that buffer.
When glVertexAttribPointer is called, then the vertex array specification is stored in the state vector of the currently bound vertex array object. The buffer which is currently bound to the target GL_ARRAY_BUFFER is associated to the attribute and the name (value) of the object is stored in the state vector of the VAO.
Further note, that the 5th parameter (stride) of glVertexAttribPointer, specifies the byte offset between consecutive generic vertex attribute.
This means before the call of glVertexAttribPointer the Vertex Array Object and the Vertex Buffer Object have to be bound.
The stride parameter has to be 5*sizeof(Glfloat), because the vertex attributes consist of the 5 GLfloat values (x, y, r, g, b).
The offset for VERTEX_ATTR_POSITION is 0 and for VERTEX_ATTR_COLOR it is 2*sizeof(GLfloat), because (r, g b) is after (x, y). Note, that GL_FLOAT is an enumerator constant and not data type, so 2*sizeof(GL_FLOAT) doesn't do what you expect it to do.
//triangle data
GLfloat vertices[] = { -0.5f, -0.5f, 1.f, 0.f, 0.f, //2 coordinates + 1 0 0 color
0.5f, -0.5f, 0.f, 1.f, 0.f,
0.0f, 0.5f, 0.f, 0.f, 1.f };
// create vertex buffer object
GLuint vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
// vertex array object
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
// specify the array of generic vertex attribute data
glBindBuffer(GL_ARRAY_BUFFER, vbo); // if "vbo" is still bound then that would not be necessary
glVertexAttribPointer(VERTEX_ATTR_POSITION, 2, GL_FLOAT, GL_FALSE, 5*sizeof(GLfloat), nullptr);
glVertexAttribPointer(VERTEX_ATTR_COLOR, 3, GL_FLOAT, GL_FALSE, 5*sizeof(GLfloat), 2*sizeof(GLfloat));
glEnableVertexAttribArray(VERTEX_ATTR_POSITION);
glEnableVertexAttribArray(VERTEX_ATTR_COLOR);
// the following is not necessary, you can let them bound
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
Make sure that the vertex attribute indices are correct:
const GLuint VERTEX_ATTR_POSITION = 3;
const GLuint VERTEX_ATTR_COLOR = 8;
3 and 8 are possible but seem strange. Not this should be the resource indices of the attributes which may be set by Layout qualifier or can be get by glGetAttribLocation after the program is linked.
By the way the coordinates for an equilateral triangle are for example:
GLfloat vertices[] = {
x y r g b
-0.866f, -0.5f, 1.f, 0.f, 0.f,
0.866f, -0.5f, 0.f, 1.f, 0.f,
0.0f, 1.0f, 0.f, 0.f, 1.f };
Can someone tell me how to draw a single white pixel at a coordinate, say (100,200)?
I am using GLUT and so far have figured out how to open a blank window. Once I figure out how to draw pixels, I will use that to implement the Bresenham line drawing algorithm. (Yes, I am aware OpenGL can draw lines. I am required to implement this myself).
#include <stdio.h>
#include <GL/glut.h>
static int win(0);
int main(int argc, char* argv[]){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_SINGLE);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
//step 2. Open a window named "GLUT DEMO"
win = glutCreateWindow("GLUT DEMO");
glClearColor(0.0,0.0,0.0,0.0); //set background
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
glutMainLoop();
}
glVertex2i(x,y);
Here is the context it needs to work:
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(80, 80);
glutInitWindowSize(500,500);
glutCreateWindow("A Simple OpenGL Program");
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluOrtho2D( 0.0, 500.0, 500.0,0.0 );
glBegin(GL_POINTS);
glColor3f(1,1,1);
glVertex2i(100,100);
glEnd();
This can be done easily by setting the scissor rectangle, and then clearing, which will only clear the specified area in the scissor rectangle. For example:
glEnable(GL_SCISSOR_TEST);
glScissor(100, 200, 1, 1);
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
// Remember to disable scissor test, or, perhaps reset the scissor rectangle:
glDisable(GL_SCISSOR_TEST);
Using modern OpenGL you can combine glScissor() with a quad that fills the entire screen.
The shaders can be as simple as:
// Vertex Shader
#version 330 core
layout (location = 0) in vec3 aPos;
void main()
{
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
}
// Fragment Shader
#version 330 core
out vec4 FragColor;
uniform vec4 inColor;
void main()
{
FragColor = inColor;
}
After doing OpenGL and Windows initialization with your preferred method (GLFW, GLAD, GLEN, etc.), create a quad (really two triangles) to cover the entire screen like:
float vertices[] = {
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
1.0f, 1.0f, 0.0f,
-1.0f, -1.0f, 0.0f,
1.0f, 1.0f, 0.0f,
-1.0f, 1.0f, 0.0f
};
Then create your buffers, compile your shaders and bind your shader program and VAO.
Then use:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Your drawing code would look something like this to draw a green pixel at x = 100, y = 100:
GLint transformLoc = glGetUniformLocation(shaderProgramId, "inColor");
glUniform4f(transformLoc, 0.0f, 1.0f, 0.0f, 1.0f);
glEnable(GL_SCISSOR_TEST);
glScissor(100, 100, 1, 1); // position of pixel
glDrawArrays(GL_TRIANGLES, 0, 6);
glDisable(GL_SCISSOR_TEST);
I wrote a tiny graphics rendering class built on top of OpenGL that has code doing exatly that. Its core function is putPixel(), which receives the x/y coordinates and a color to draw a single pixel on the screen. Feel free to take a look at the code: https://github.com/amengol/MinGL
I wrote a code in VC++ 2013, and when debugging it, the 'argc' argument of main function gets an abnormal big value. A value higher than 2,000,000,000 always!! But every time has value different from previous run. I checked the 'Command Arguments' field in project properties, it is empty.
How can i solve the problem?
If any more details is needed tell me.
Thanks.
the code:
#include <stdio.h>
#include <stdlib.h>
//for Windows, we use the static version of GLEW
#ifdef _WIN32
#define GLEW_STATIC
#endif
//GLFW and GLEW libraries
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include "shader.h" // functions to load shader
//Global variables
GLFWwindow* window;
int main(int argc, char **argv)
{
//Initialize GLFW
if (!glfwInit()){
fprintf(stderr, "Failed to initialize GLFW\n");
exit(EXIT_FAILURE);
}
//enable anti-aliasing 4x with GLFW
glfwWindowHint(GLFW_SAMPLES, 4);
//specify the client API version that the created context must be compatible with.
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
//make the GLFW forward compatible
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
//use the OpenGL Core (http://www.opengl.org/wiki/Core_And_Compatibility_in_Contexts)
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
//create a GLFW windows object
window = glfwCreateWindow(640, 480, "Chapter 4 - GLSL", NULL, NULL);
if (!window){
fprintf(stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n");
glfwTerminate();
exit(EXIT_FAILURE);
}
//make the context of the specified window current for the calling thread
glfwMakeContextCurrent(window);
glfwSwapInterval(100);
glewExperimental = true; // Needed for core profile
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Final to Initialize GLEW\n");
glfwTerminate();
exit(EXIT_FAILURE);
}
GLuint program = LoadShaders("simple.vert", "simple.frag");
glBindFragDataLocation(program, 0, "color_out");
glUseProgram(program);
// Create Vertex Array Object
GLuint vertex_array;
glGenVertexArrays(1, &vertex_array);
glBindVertexArray(vertex_array);
// Create a Vertex Buffer Object and copy the vertex data to it
GLuint vertex_buffer;
GLuint color_buffer;
glGenBuffers(1, &vertex_buffer);
glGenBuffers(1, &color_buffer);
const GLfloat vertices[] = {
+1.0f, +0.0f, 0.0f,
+1.0f, -1.0f, 0.0f,
+0.0f, -1.0f, 0.0f,
-1.0f, -0.0f, 0.0f,
+0.0f, +1.0f, 0.0f,
-1.0f, +1.0f, 0.0f,
};
const GLfloat colors[] = {
0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f,
1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
};
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, color_buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW);
// Specify the layout of the vertex data
GLint position_attrib = glGetAttribLocation(program, "position");
glEnableVertexAttribArray(position_attrib);
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
glVertexAttribPointer(position_attrib, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
GLint color_attrib = glGetAttribLocation(program, "color_in");
glEnableVertexAttribArray(color_attrib);
glBindBuffer(GL_ARRAY_BUFFER, color_buffer);
glVertexAttribPointer(color_attrib, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
while (!glfwWindowShouldClose(window)){
// Clear the screen to black
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// Draw a rectangle from the 2 triangles using 6 vertices
glDrawArrays(GL_TRIANGLES, 0, 24); //draw the square
glfwSwapBuffers(window);
glfwPollEvents();
}
//clear up the memories
glDisableVertexAttribArray(position_attrib);
glDisableVertexAttribArray(color_attrib);
glDeleteBuffers(1, &vertex_buffer);
glDeleteBuffers(1, &color_buffer);
glDeleteVertexArrays(1, &vertex_array);
glDeleteProgram(program);
// Close OpenGL window and terminate GLFW
glfwDestroyWindow(window);
glfwTerminate();
exit(EXIT_SUCCESS);
}
Edit:
I removed pieces of code till reached the following code. Interestingly, if I remove glewExperimental = true; from code, some link error (error LNK2001) rises!
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
#define GLEW_STATIC
#endif
//GLFW library
#include <GL/glew.h>
int main(int argc, char **argv)
{
glewExperimental = true; // Needed for core profile
exit(EXIT_SUCCESS);
}
So I've been toying around with OpenGL under QML and have been looking at the supplied example file of the same name. I kind of understand how it's working but here's the thing: I tried to replace the OpenGL Shader Program that was in the paint() function of the example with my own very basic Open GL stuff. However I was unable to get anything visible on the screen. The only thing I was able to change was the color of the background. So I'm wondering how do I set up the viewport, the camera, and whatever is needed to have something on the screen. I have some (very rusty) experience on OpenGL but in the past there's always been things like freeglut that makes life a bit easier. Any pointers or examples (something I can put in the paint() method to observe and learn from) to the right direction would be much appreciated...
Edit: So here's what I have in the paint() method:
void QtOpenGLViewRenderer::paint()
{
// The following two lines fixed the problem
QOpenGLFunctions glFuncs(QOpenGLContext::currentContext());
glFuncs.glUseProgram(0);
glViewport(0, 0, m_viewportSize.width(), m_viewportSize.height());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0.2, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
GLfloat triangle[] = {
0.25f, 0.25f, 0.0f,
0.75f, 0.25f, 0.0f,
0.25f, 0.75f, 0.0f
};
GLfloat colors[] = {
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f
};
glVertexPointer(3, GL_FLOAT, 0, triangle);
glColorPointer(4, GL_FLOAT, 0, colors);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glShadeModel(GL_SMOOTH);
glDrawArrays(GL_TRIANGLES, 0, 3);
glFlush();
}
All I see is the dark reddish background but no sign of the triangle. Why is this?
Answering my own question for the record. The problem was that Qt by default is expecting new OpenGL Shading Language (GLSL) style instructions. To get old style OpenGL instructions to work you need to tell Qt that you're going to use them instead of a program defined by shaders. This is done by issuing the following commands:
QOpenGLFunctions glFuncs(QOpenGLContext::currentContext());
glFuncs.glUseProgram(0);
For these to work you also need to include the following headers:
#include <QOpenGLFunctions>
#include <QOpenGLContext>
I am trying to display a simple triangle with OpenGL (I am using freeglut3-dev and libglew1.6 on Ubuntu 12.04 and coding in NetBeans 7.2). The code compiles and links with no problems, but displays only a blank screen (with initialized colour) but only a single white point at the origin (instead of 3 points for each of the triangle vertices). My code is below:
#include <stdio.h>
#include <GL/glew.h>
#include <GL/freeglut.h>
#include "math_3d.h"
GLuint VBO;
static void RenderSceneCB()
{
glClear(GL_COLOR_BUFFER_BIT);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
glutSwapBuffers();
}
static void InitializeGlutCallbacks()
{
glutDisplayFunc(RenderSceneCB);
}
static void CreateVertexBuffer()
{
Vector3f Vertices[3];
Vertices[0] = Vector3f(-1.0f, -1.0f, 0.0f);
Vertices[1] = Vector3f(1.0f, -1.0f, 0.0f);
Vertices[2] = Vector3f(0.0f, 1.0f, 0.0f);
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
glutInitWindowSize(1024, 768);
glutInitWindowPosition(100, 100);
glutCreateWindow("Tutorial 03");
InitializeGlutCallbacks();
// Must be done after glut is initialized!
GLenum res = glewInit();
if (res != GLEW_OK) {
fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
return 1;
}
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
CreateVertexBuffer();
glutMainLoop();
return 0;
}
Here is a screenshot of what I see:
Here is a picture of what it should look like:
I am following this tutorial. Vector3f is just a structure with three data members: x, y, z.
Read the next chapter of the tutorial, it explains it all.
A vertex is simply a set of attributes, which are referenced by their number (0 in your case). This number however doesn't tell the GL what the data are, and thus how to use them. With the old API you had specific vertex specification functions for each attribute; glVertexPointer() was used to provide position attributes, glTexCoordPointer() texture coordinates, etc. Today it is up to you to use the attributes the way you want, through shaders, which are explained in the next chapter of your tutorial.