Category Archives: Development

Embedding SDL 2 in QT widget

Having scoured the web and found nothing but useless information I thought I should share my solution to embedding a SDL 2 window inside a QT widget. The following code will embed a SDL window inside a ‘openGLWidget’ under the main window ‘central widget’ and display a red background.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
#include "mainwindow.h"
 
MainWindow::MainWindow(QWidget *parent)
	: QMainWindow(parent),
	ui(new Ui::MainWindowClass)
{
	ui->setupUi(this);
	show();
	image_w_ = 960;
	image_h_ = 544;
 
	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {
		fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
		exit(1);
	}
	ui->openGLWidget->resize(image_w_, image_h_);
	sdlWindow = SDL_CreateWindowFrom((void*)ui->openGLWidget->winId());
	if (!sdlWindow) {
		fprintf(stderr, "SDL: failed to create window: %s\n", SDL_GetError());
	}
	sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, NULL);
	if (!sdlWindow) {
		fprintf(stderr, "SDL: failed to create renderer: %s\n", SDL_GetError());
	}
	sdlTexture = SDL_CreateTexture(sdlRenderer,
		SDL_PIXELFORMAT_IYUV,
		SDL_TEXTUREACCESS_STREAMING,
		image_w_,
		image_h_);
	if (!sdlTexture) {
		fprintf(stderr, "SDL: failed to create SDl texture - exiting\n");
	}
	SDL_SetRenderDrawColor(sdlRenderer, 255, 0, 0, 255);
	SDL_RenderClear(sdlRenderer);
	SDL_RenderPresent(sdlRenderer);
}
 
MainWindow::~MainWindow()
{
 
}

Build static QT 5.1 on Windows

So I needed to built QT statically for my cube world server app as otherwise the injected DLL would crash and building it statically just seemed like a better option with not having to deploy several separate library’s with the core application. However, reading through many (dated) tutorials all I could manage to summon were some generic errors, eventually I managed to find a straightforward and simple solution which I thought I should post to help out anyone wanting to build the latest 5.1 release.

Before you go any further make sure you have visual studio 2012 installed, the express version wont work so if you have that already you’ll need to upgrade.

1) Download the QT source – I got mine from HERE

2) Extract the whole contents to somewhere e.g “C:\Qt\” so you end up with “C:\Qt\qt-everywhere-opensource-src-5.1.0”

3) Install the DirectX SDK – Download HERE. If you get the error “S1023” on install load up a command prompt and enter the following and try again.

MsiExec.exe /passive /X{F0C3E5D1-1ADE-321E-8167-68EF0DE699A5}
MsiExec.exe /passive /X{1D8E6291-B0D5-35EC-8441-6616F567A0F7}

4) Once installed go to the DirectX SDK install directory (C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)) then “Utilities” then “bin” so you’ll end up somewhere like this “C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Utilities\bin”

5) you should now see a file called “dx_setenv.cmd” right click this and run as admin, this will setup the path to our DirectX install.

6) Now download Jom from HERE and extract it to the main qt source directory we extracted earlier so “C:\Qt\qt-everywhere-opensource-src-5.1.0”

7) Next open up a new Visual Studio command prompt (can be found under the visual studio tools folder in the start menu) and navigate to the previous source directory where we just extracted jom to

cd C:\Qt\qt-everywhere-opensource-src-5.1.0

8) Enter the following line and press enter, this will set up our build config

configure -debug-and-release -static –opensource -opengl desktop -nomake examples -nomake tests

9) Finally type jom press enter then wait, this might take a while but once its done you should have a fully working static QT build under the “qtbase” directory!

Twisted.

Lua + Luadec 4 byte float number

I recently needed to build lua/luadec to support 4 byte floats instead of the usual 8 byte doubles for a personal project which proved to be more of a pain than I expected, mainly due to setting up an enviroment in which luadec didn’t kick out 1000+ errors at compile time.

So, in case anyone out there needs to do the same I’ve uploaded the project to the link below. Source and binaries are included, if you need to recompile just load up mingw32 and run these commands.

 cd lua-5.1.4
 cd src
 mingw32-make mingw
 cd luadec
 mingw32-make

[DOWNLOAD]