Use SDL inside Irrlicht - c++

I know you can do the same in lrrlicht, but I want to use SDL code/ functions to draw text, images inside Irrlicht (to handle 2d) and use Irrlicht to do the hardcore 3D thing, how can you apply text or images from sdl to this Irrlicht Engine, can you show me simple code, so that I can understand?
In the SDL you can do such:
// I start by declare the SDL video Name
SDL_Surface *screen;
// set the video mode:
screen = SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF | SDL_FULLSCREEN); if (screen == NULL) { printf("Unable to set video mode: %s\n", SDL_GetError()); return 1; }
// I can now display data, image, text on the screen by using the declared SDL video Name " screen "
SDL_BlitSurface(my_image, &src, screen, &dest);

If you are using / targeting Windows , and are a little familiar with the WinApi, you may be able to use SDL with Irrlicht by running both inside a Win32 Window, using a combination of the SDL Window ID Hack (also see this thread) and running Irrlicht in a Win32 Window. The only problems you may face is that running SDL in a Win32 Window is extremely difficult and unpredictable.
You may be also be able to achieve a similar result using GTK+ (for cross-platform purposes), but I have personally never succeeded in running SDL or Irrlicht in a GTK+ Window.
Also, if you want a light graphics and media library like SDL , may I suggest SFML. It can run in Win32 and X/11 windows without any problems and may easily work with Irrlicht.

Related

Is there a performance difference in using an OpenGL window like GLFW or a surrounding window like GTK or SDL?

vlc has an impressive example showing how to integrate with gtk:
https://git.videolan.org/?p=vlc.git;a=blob;f=doc/libvlc/gtk_player.c
but we are using glfw and C++. If we were to create a wrapper window using a windowing toolkit like gtk, is there any performance penalty in terms of the OpenGL operating within it?
Is it possible to open a video window within the GTKGL component, or does OpenGL interfere with video even if it is not rendering?
If you pass the window handle to libvlc, I don't see why there would be performance differences.

How can I modify the sdl2 window frame?

I am using sdl2 in c++, and want to modify the window frame in my application. Can this be achieved and implemented?
I had a look here: How to change window style/theme in c++ - but I'm not sure how it can mix in.
#include "SDL.h"
SDL_Window *window;
void main()
{
window = SDL_CreateWindow("TEST", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN);
SDL_Delay(3000);
}
I would like to build in a file menu and edit menu to the actual frame on the header and possibly change the color or make tabs in the frame as with google chrome.
One of SDL's main goals is to abstract window creation, so you don't have to deal with each OS's little tweaks. Said that, I don't think there is a portable, clean way to that using SDL.
What I would do is to go down the level of abstraction: Use WinAPI or MFC or one of Microsoft abstractions over the WinAPI to actually customize the window and then use DirectX or OpenGL to do all graphics. You can still use SDL for audio, input, etc. though.

SDL2 and OpenGL functions with two windows

I am trying to make one application with two windows with SDL2. To make draw process faster and capable to run 3d animations I am using OpenGL. But when I open second window, how can I said to OpenGL (gl functions) to draw in second window?
I searched into libsdl wiki but cant find anything.
You are looking for the SDL_GL_MakeCurrent function.
Use this function to set up an OpenGL context for rendering into an OpenGL window.
Example:
SDL_GL_MakeCurrent(window, gl_context);
// OpenGL functions will draw to window
// ...
SDL_GL_MakeCurrent(window2, gl_context);
// OpenGL functions will draw to window2

OpenGL in my HWND

Right now, I'm trying to port a Direct3D renderer from my engine. I'm and OpenGL begginer so i dont have much knowlegde about OpenGL, as now i can create windows and do my render via glut, but i can't use glut for my project, because the HWND is created in my code and then sent to the renderer DLL
// Where pWindow is already a valid HWND target of the renderer
//(Currently Direct3D9 and Direct3D10
pRenderer = pCreateGraphics(800, 600, false, pWindow);
My question is: Is there library similar to GLUT that has a similar behaviour as GLUT, but allowing my to use my own window handle?
Note: I prefer using a lib instead of reinventing the wheel, but i will do if there is not a library that can help me
Well you can have a look at GLFW's source code or NeHe tutorials and grab the OpenGL init code.
SDL lets you get the window handle.
I don't know if the used pixel format can be assumed to be DirectX compatible though.

How do I use Qt and SDL together?

I am building a physics simulation engine and editor in Windows. I want to build the editor part using Qt and I want to run the engine using SDL with OpenGL.
My first idea was to build the editor using only Qt and share as much code with the engine (the resource manager, the renderer, the maths). But, I would also like to be able to run the simulation inside the editor. This means I also have to share the simulation code which uses SDL threads.
So, my question is this: Is there a way to have an the render OpenGL to a Qt window by using SDL?
I have read on the web that it might be possible to supply SDL with a window handle in which to render. Anybody has experience dong that?
Also, the threaded part of the simulator might pose a problem since it uses SDL threads.
This is a simplification of what I do in my project. You can use it just like an ordinary widget, but as you need, you can using it's m_Screen object to draw to the SDL surface and it'll show in the widget :)
#include "SDL.h"
#include <QWidget>
class SDLVideo : public QWidget {
Q_OBJECT
public:
SDLVideo(QWidget *parent = 0, Qt::WindowFlags f = 0) : QWidget(parent, f), m_Screen(0){
setAttribute(Qt::WA_PaintOnScreen);
setUpdatesEnabled(false);
// Set the new video mode with the new window size
char variable[64];
snprintf(variable, sizeof(variable), "SDL_WINDOWID=0x%lx", winId());
putenv(variable);
SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
// initialize default Video
if((SDL_Init(SDL_INIT_VIDEO) == -1)) {
std:cerr << "Could not initialize SDL: " << SDL_GetError() << std::endl;
}
m_Screen = SDL_SetVideoMode(640, 480, 8, SDL_HWSURFACE | SDL_DOUBLEBUF);
if (m_Screen == 0) {
std::cerr << "Couldn't set video mode: " << SDL_GetError() << std::endl;
}
}
virtual ~SDLVideo() {
if(SDL_WasInit(SDL_INIT_VIDEO) != 0) {
SDL_QuitSubSystem(SDL_INIT_VIDEO);
m_Screen = 0;
}
}
private:
SDL_Surface *m_Screen;
};
Hope this helps
Note: It usually makes sense to set both the min and max size of this widget to the SDL surface size.
While you might get it to work like first answer suggest you will likely run into problems due to threading. There is no simple solutions when it comes to threading, and here you would have SDL Qt and OpenGL mainloop interacting. Not fun.
The easiest and sanest solution would be to decouple both parts. So that SDL and Qt run in separate processes and have them use some kind of messaging to communicate (I'd recommend d-bus here ). You can have SDL render into borderless window and your editor sends commands via messages.
Rendering onto opengl from QT is trivial (and works very well)
No direct experience of SDL but there is an example app here about mixing them.
http://www.devolution.com/pipermail/sdl/2003-January/051805.html
There is a good article about mixing QT widgewts directly with the opengl here
http://doc.trolltech.com/qq/qq26-openglcanvas.html a bit beyond what you strictly need but rather clever!