glBindFramebuffer not defined? - c++

I have reinstalled Code::Blocks and GLFW3 after finally growing tired of not being able to experiment and do stuff in c++ on my pc for about one or two months, I got far enough to where I am trying to make a simple window that gets cleared. The problem is that the window doesn't get cleared at all except for pitch black darkness. At first I thought it might be because I use a function to draw the window, but that wasn't the issue either. I tried adding glBindFramebuffer(GL_FRAMEBUFFER,0); before the clear to see if that would fix the issue, but then the compiler said that glBindFramebuffer wasn't declared.
Here's main.cpp
#include <GLFW/glfw3.h>
void loop(GLFWwindow* window,bool &quit);
int main()
{
glfwInit();
glfwWindowHint(GLFW_VERSION_MAJOR,4);
glfwWindowHint(GLFW_VERSION_MINOR,5);
GLFWwindow* window=glfwCreateWindow(512,512,"Test",NULL,NULL);
glClearColor(1.0f,1.0f,1.0f,1.0f);
bool quit=false;
do
{
loop(window,quit);
}while(quit==false);
glfwTerminate();
return 0;
}
And loop.cpp
#include <GLFW/glfw3.h>
void loop(GLFWwindow* window,bool &quit){
glfwPollEvents();
if(glfwGetKey(window,GLFW_KEY_ESCAPE)==GLFW_PRESS)
quit=true;
glBindFramebuffer(GL_FRAMEBUFFER,0); <-Error here
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
}
EDIT: So after figuring out I need to load functions I've tried GLEW to no avail, GL3W doesn't seem to work in linux and all other options seems to be too god damned advanced for what it is and won't work in anyways.

Related

glfwInit needs to be called twice for shared libraries, why would that be?

Experimenting around I found something interesting let's say we have A.cpp and B.cpp A.cpp in pseudocode is something like this:
// Load library
void (*InitializeRendering)(GLFWwindow*);
InitializeRendering = (decltype(InitializeRendering)) dlsym(renderer_handle, INIT_RENDERING_FUNC);
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
auto window = glfwCreateWindow(800, 800, "Vulkan window", nullptr, nullptr);
InitializeRendering(window);
And then B.cpp
extern "C"
{
void InitializeRendering(GLFWwindow* window)
{
glfwInit();
// Init vulkan surface from window
}
This setup works, what's interesting is, if you delete the call to glfwInit() inside B.cpp things won't work anymore, you very much need to have it initialized in the shared library object. I am wondering why this would be the case? It seems that the global state between the 2 binaries is not shared.

Qt5, Ubuntu. Failure in building an app with Opengl

I'm a novice in Qt5, want to make a simple programm with interactive 3D graphics. I create a new Qt Widgets app, following manuals I do QT += opengl in .pro, #include<QtOpenGL> in .h, and that's all. I even don't add any extra code, I click "build project" and get this:
/opt/qtsdk/5.5/gcc/include/QtGui/qopenglext.h:117: ошибка: typedef
'PFNGLDRAWRANGEELEMENTSPROC' is initialized (use decltype instead)
typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode,
GLuint start, GLuint end, GLsizei count, GLenum type, const void
*indices); 'GLenum' was not declared in this scope 'GLuint' was not declared in this scope 'GLsizei' was not declared in this scope
'GLenum' was not declared in this scope expected primary-expression
before 'const' typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC)
(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type,
const void *indices); typedef 'PFNGLTEXIMAGE3DPROC' is initialized
(use decltype instead) typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC)
(GLenum target, GLint level, GLint internalformat, GLsizei width,
GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum
type, const void *pixels);
and same on and on till I stop building as I get the 8140th error, which isn't the last. :\
Please, help!! Tried everything, can't take it anymore
I installed Qt5 (lib and IDE together) by online-installation, then tried to fix them:
$ apt-get install libgl1-mesa-dev
$ sudo aptitude install mesa-common-dev
$ sudo apt-get install build-essential libfontconfig1
etc. Tried everything, that managed to find regarding my problem (though google says nothig useful solving exactly my problem)
OS: Linux Mint 17.1 Cinnamon 32bit
Video card: Intel Corporation 2nd Generation Core Processor Family Integrated Graphics Controller (Total crap. Maybe, that's an issue?)
OpenGL version: 3.0 Mesa 10.1.3 (Does QtOpengl use a default Оpengl, preinstalled on my laptop, or uses its own Opengl? Though, how do versions of Opengl and Qt correlate? Would Qt4-5 even work witn an old Opengl version?)
Qt version: 4.8.6 (At least console says so, but I'm not shure that projects aren't built with Qt5 libs. How can I explicitly specify the version I need to build the project by the way?)
Auto-detected Qt version: Desktop Qt 5.5.1 GCC 32bit
QMake version: 2.01a
Auto-detected compiler: GCC; debugger: GDB
Need your help very much! Thanks
The only code I have:
That's mainscene.h:
#ifndef MAINSCENE_H
#define MAINSCENE_H
#include <QMainWindow>
#include<QtOpenGL>
#include<QGLWidget>
class MainScene : public QMainWindow
{
protected:
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
public:
Scene3D(QWidget* parent = 0);
};
#endif // MAINSCENE_H
That's the SimpleOpengl.pro:
QT += core gui
QT += opengl
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = SimpleOpengl
TEMPLATE = app
SOURCES += main.cpp
mainscene.cpp
HEADERS += mainscene.h
That's the main.cpp:
#include "mainscene.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainScene w;
w.show();
return a.exec();
}
(It's all wrong, isn't it?..)

Unable to include C++ headers in Code::Blocks SDL program?

I am trying to execute a bare bones SDL program. I followed the instructions in tutorial here.
Program builds and executes as expected with C headers(stdlib.h for printf()). But it throws me an error when i try to use iostream(for cout). Build message says "fatal error: iostream: No such file or directory".
How to use C++ features with SDL2? It wont even allow me to use bool or classes. Program executes just fine when i use C functions and data types.
I have Code::Blocks 16.01 and SDL 2.05.
I am new to SDL and all these stuff , please dont be rude. I know question might sound silly to you guys. I searched for solution here and didn't found any relevant answer related to this. If SDL installation is incorrect, please point the correct steps. I would be grateful if someone helps me to figure this out! Thanks.
Sorry for poor English, please comment if question sounds unclear.
P.S: This code executes for me because i commented out C++ part.
#include<SDL.h>
#include<stdlib.h>
//#include<iostream>
//using namespace std;
const int screen_width=250;
const int screen_height=500;
int main(int argc,char* args[])
{
SDL_Window *window=NULL;
//SDL_Window is new data type. Always initialize pointer to NULL.
SDL_Surface* screenSurface=NULL;
//SDL_Surface is new data type. Surface is just a 2d image
//cant call any SDL function without initializing it before..
if(SDL_Init(SDL_INIT_VIDEO)<0)
{
}
//cout<<"SDL could not be initialized! Error:"<<SDL_GetError();
else
{
//creating a window
window=SDL_CreateWindow("SDL Tutorial",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,screen_width,screen_height,SDL_WINDOW_SHOWN);
//just a error check again. make it habit to check for error always!!
if(window==NULL)
{
//cout<<"Sorry window could not be created!"<<SDL_GetError();
}
else
{
//get window surface. surface of window of type SDL_Window is returned to type of surface of SDL_Surface
screenSurface=SDL_GetWindowSurface(window);
//fill the surface
SDL_FillRect(screenSurface,NULL,SDL_MapRGB(screenSurface->format,0xFF,0xFF,0xFF));
//update the surface!, you always need to update surface !!
SDL_UpdateWindowSurface(window);
//wait for defined amount of time! time is in millisecs
SDL_Delay(2000);
//destroy window
SDL_DestroyWindow(window);
//quite SDl subsystems
SDL_Quit();
}
}
return 0;
}

Fmod constans (FMOD_HARDWARE) not found

I am using FMOD in Ubuntu to play sound in my game.
I have the next
#include "SoundEngine.h"
bool SoundEngine::initSystem()
{
System_Create(&system);// create an instance of the game engine
system->init(32, FMOD_INIT_NORMAL, 0);// initialise the game engine with 32 channels
//load sounds
system->createSound("Media/NoMoreMagic.ogg", FMOD_HARDWARE, 0, &sound1);
sound1->setMode(FMOD_LOOP_OFF); /* drumloop.wav has embedded loop points which automatically makes looping turn on, */
/* so turn it off here. We could have also just put FMOD_LOOP_OFF in the above CreateSound call. */
system->playSound(FMOD_CHANNEL_FREE, sound1, false, 0);
return true;
}
And the SoundEngine.h is:
#ifndef SOUNDENGINE_H_
#define SOUNDENGINE_H_
#include "FMOD/inc/fmod.hpp" //fmod c++ header
#pragma comment( lib, "fmodex_vc.lib" ) // fmod library
using namespace FMOD;
class SoundEngine{
public:
bool initSystem(void);
private:
//FMod Stuff
System *system; //handle to FMOD engine
Sound *sound1, *sound2; //sound that will be loaded and played
};
#endif /* SOUNDENGINE_H_ */
THe problem is that FMOD_HARDWARE or FMOD_CHANNEL_FREE is not found.
Anyone knows where are they?
EDIT: Another thing is that the pragma comment throws a warning telling that ignore pragma. Maybe the problem has relation with the pragma? How can I fix the pragma?
I believe FMOD_HARDWARE is from the older FMOD Ex API. Are you using FMOD 5? In my calls to System::createSound I use FMOD_DEFAULT or FMOD_CREATESAMPLE (the latter will load the entire sound and decompress it in memory, to speed up playback) which seems to use the hardware well. For your playSound call, try
FMOD::Channel *channel;
system->playSound(sound1, NULL, false, &channel);

What is the correct way to include GLEW in a Mac OS X .framework?

Probably a very simple problem, but it's had me stumped.
I've got an SDL/OpenGL/GLEW based static library that compiles (gcc/g++) and links fine on Windows. On OS X, the same codebase fails to compile claiming that it can't find the declaration of GL_NUM_EXTENSIONS and ::glGetStringi() - which is since I've thrown GLEW in the mix (with only SDL and OpenGL, it builds fine on OS X too).
// globals.h
#include <glew.h>
#include <SDL/SDL.h>
// graphics.h
#include "globals.h"
bool HasGLExtension(const char* pName);
// graphics.cpp
#include <string>
#include "graphics.cpp"
bool HasGLExtension(const char* pName)
{
GLint numExtensions;
::glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); // error
for (int i = 0; i < numExtensions; ++i)
{
if (strcmp(pName, (char*)::glGetStringi(GL_EXTENSIONS, i)) == 0) // error
{
return true;
}
}
return false;
}
the dependent libraries, built as frameworks, are situated at /Library/Frameworks.
the -DGLEW_STATIC -DSDL_NO_GLEXT compile flags are used (as needed on Windows - the problem persists even if I remove them).
even auto-completion confirms that the location of glew.h exists (then again, of course, that's not the error I'm getting -- it's the symbols).
including SDL/SDL_opengl.h will just result in conflicting declarations.
the problematic definitions are present in glew.h
What's the obvious that I'm missing?
Don't do it. For something that 1, is easy to set up and 2, works out of the box and 3, has little to no encumbrance in its licensing, use glLoadGen.