Hi there,
i just startet to re-discover C++ and openGL. (I haven't used both for years). Since SFML seems to be simple and portable, I decided to use it for graphics development.
No I started writing some openGL code.
so, to keep it simple: i'm too stupid for rendering an array in 3d..
this is what i currently have and it works:
/*
* SceneGraph.cpp
*
* Created on: 21.01.2018
* Author:
*/
#include "SceneGraph.h"
namespace frac {
SceneGraph::SceneGraph(bool f) : width(0), height(0), fullscreen(f),universe() {}
SceneGraph::SceneGraph(int w, int h, bool f) : width(w), height(h), fullscreen(f),universe() { }
void SceneGraph::run() {
// fullscreen or windowed mode
uint32_t style = (fullscreen) ? sf::Style::Fullscreen : sf::Style::Default;
// style
sf::ContextSettings settings;
settings.depthBits = 24;
settings.stencilBits = 8;
settings.antialiasingLevel = 0;
settings.majorVersion = 3;
settings.minorVersion = 0;
// set video mode if neccessary
sf::VideoMode mode = sf::VideoMode::getDesktopMode();
if (width != 0 && height != 0){
mode = sf::VideoMode(width, height);
}
// create window
sf::RenderWindow window(mode, "SFML works!", style, settings);
// framerate control
window.setVerticalSyncEnabled(true); // call it once, after creating the window
window.setFramerateLimit(60); // call it once, after creating the window
// mainloop
while (window.isOpen())
{
/*
* get and handle events
*/
sf::Event event;
while (window.pollEvent(event))
{
switch(event.type) {
case sf::Event::Closed:
window.close();
break;
default:
break;
}
}
show();
window.display();
}
}
/**
* rendert irgendwas
*/
void SceneGraph::show() {
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
this->vertice = {
0.0f, 0.5f, 0.0f, // top
0.5f, -0.5f, 0.0f, // bottom right
-0.5f, -0.5f, 0.0f, // bottom left
};
GLuint vbuf;
glGenBuffers(1, &vbuf);
glBindBuffer(GL_ARRAY_BUFFER, vbuf);
std::cout << " a:" << glGetError() ;
glEnableClientState(GL_VERTEX_ARRAY);
std::cout << " b:" << glGetError() ;
glBufferData(GL_ARRAY_BUFFER, this->vertice.size(), &(this->vertice[0]), GL_STATIC_DRAW);
std::cout << " c:" << glGetError() ;
glInterleavedArrays(GL_V3F, this->vertice.size(), 0);
std::cout << " d:" << glGetError() ;
glDrawArrays(GL_TRIANGLES, 0, this->vertice.size());
std::cout << " e:" << glGetError() ;
glDeleteBuffers(1, &vbuf);
std::cout << " z:" << glGetError() << std::endl;
}
} /* namespace frac */
running this, my screen is blank. the geterrors always result 0.
wondering if my vertex coordinates are wrong I tried this:
void SceneGraph::show() {
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
this->vertice = {
0.0f, 0.5f, 0.0f, // top
0.5f, -0.5f, 0.0f, // bottom right
-0.5f, -0.5f, 0.0f, // bottom left
};
glBegin(GL_TRIANGLES);
glVertex3fv(&vertice[0]);
glVertex3fv(&vertice[3]);
glVertex3fv(&vertice[6]);
glEnd();
}
but this works..
vertice is, btw. a std::vector.