PrevUpHomeNext

glbinding and sfml


glbinding and sfml - Posted on Jun 29, 2024 - See https://glbinding.org - Logs Home - d0026

glbinding and sfml

Create Window using sfml, and leverages glbinding.

glbinding is a c++ binding for the OpenGL API, generated using the gl.xml specification.

glbinding leverages C++11 features like enum classes, lambdas, and variadic templates, instead of relying on macros; all OpenGL symbols are real functions and variables. It provides type-safe parameters, per-feature API headers, lazy function resolution, multi-context and multi-thread support, global and local function callbacks, meta information about the generated OpenGL binding and the OpenGL runtime, as well as tools and examples for quick-starting your projects. Based on the OpenGL API specification (gl.xml) glbinding is generated using scripts and templates that can be easily adapted to fit custom needs.

cpp example code

c++ example code.

#include <glbinding/gl45core/gl.h>	// gl 4.5
#include <glbinding/Binding.h>	// glbinding::Binding
#include <SFML/Window.hpp>
#include <iostream>
#include <glbinding/Version.h>	// glbinding::Version
#include <glbinding/Meta.h>	// glbinding::Meta::versions
#include <future>

auto fn = []
{
	static int id_generator = -1;
	++id_generator;
	const int id = id_generator;
	glbinding::Binding::initialize(id, glbinding::getProcAddress);
	gl45core::glClearColor((50*id)/255.0, (100*id+50)/255.0, (200*id+50)/255.0, 0.0);

	std::cout << "glbinding thread is created! id: " << id << std::endl;
};

int main()
{
	sf::Window window{sf::VideoMode{1280, 720, 32}, "glbinding"};

	glbinding::Binding::initialize();

	{ // try
		gl45core::GLuint program = gl45core::glCreateProgram();
		gl45core::GLuint shader = gl45core::glCreateShader(gl45core::GL_COMPUTE_SHADER);
		gl45core::GLuint shader2 = gl45core::glCreateShader(gl45core::GL_VERTEX_SHADER);
		gl45core::GLuint shader3 = gl45core::glCreateShader(gl45core::GL_FRAGMENT_SHADER);

		gl45core::glBindAttribLocation(program, 0, "in_vertex");
		gl45core::glBindAttribLocation(program, 1, "in_tex_coord");

		std::cout << program <<" : " << shader << " : " << shader2 << " : " << shader3 << std::endl;
	}
	
	{ // try
		for (const glbinding::Version & version: glbinding::Meta::versions())
		{
			std::cout << version << std::endl;
		}
	}
	
	{ // try
		auto thread1 = std::async(fn);
		auto thread2 = std::async(fn);
	}

	gl45core::glClearColor(0.3f, 0.5f, 0.8f, 0.0f);

	while (window.isOpen())
	{
		gl45core::glClear(gl45core::GL_COLOR_BUFFER_BIT | gl45core::GL_DEPTH_BUFFER_BIT);
		window.display();
		sf::Event event;
		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed)
				window.close();
		}
	}
}

This program will open a blue window normally and safely, then print the following information:

1 : 2 : 3 : 4
1.0
1.1
1.2
1.3
1.4
1.5
2.0
2.1
3.0
3.1
3.2
3.3
4.0
4.1
4.2
4.3
4.4
4.5
glbinding thread is created! id: 0
glbinding thread is created! id: 1

See Also

c++ glbinding

c++ sfml

std::cout

cpp/c++

c++ std::exception:

std::cout.write(err.data(), err.size());

std::cout << std::endl;

caught:

  ===================================
  #  The c++ programming language.  #
  #                                 #
  #  Join c++ Discord: yZcauUAUyC   #
  #  Deck                           #
  ===================================

Home: cppfx.xyz

K


PrevUpHomeNext