Hello,
I wasn’t sure where to go with my problem as I’m not sure if it’s a strictly OpenGL or C++ problem. Here’s my story.
I made a console application that controls some servomotors via a rs232 port. All in all the program gets a joystick status from a controller device, opens a RS port, sends a command to the servocontroler and closes the port /and does other maintenance stuff, but that’s not important/.
The thing is, that the joystick needs to be set up right to work correctly and this is where I decided to create a ‘setup’ image which would show the user how to set up the controller correctly. That is why I decided to create a OpenGl window, put in the image and at the start of the program display it to the user so that he can configure everything correctly before going any further. So I though to myself ‘no biggy’ I’ll copy-paste a simple tutorial program which opens a OpenGL window /at first just opens it. nothing more/.
Imagine my surprise when the window opened, but the console app froze, and after closing the window, the app closed as well /yeah. now it’s clear to me why it happened, back then I though the OpenGL window was a different process/. So now I’m left with a problem and no real idea how to handle it. I’m not keen on creating threads, but I did manage to create them using CreateThread () but here’s the thing, I can pass only one parameter to the thread, and I saw glutInit uses 2:
glutInit(&argc, argv);
plus I can’t seem to run functions inside a thread as I get an error:
error C2601: ‘init’ : local function definitions are illegal
and putting those functions outside the thread gives an:
error C3861: ‘glutInit’: identifier not found
error
I’m in a jam and if someone could help me I would be really grateful. Here’s how the code looks like is someone would like to get a better perspective:
//glowne
#include <stdio.h>
#include <cstdlib>
#include <iostream>
//joystick i port szeregowy = sterowanie pojazdem
#include "../joystick.h"
#include "../Serial.h"
#include <conio.h>
#include <tchar.h>
Joystick* joysticks[4];
unsigned int i;
unsigned int j;
int ch;
CSerial serial;
LONG lLastError = ERROR_SUCCESS;
//zmienne dla serwomechanizmow
int serwa[3];
unsigned char str[4];
unsigned char wychyl_poziom = str[2], wychyl_pion = str [2];
//GLUT
#include "stdafx.h"
#include "windows.h"
#include <gl/gl.h>
//funkcje OpenGL
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC);
void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC);
// funkcja pobodu liczby joystickow
unsigned int numJoysticks = Joystick::deviceCount();
[b]****** CODE STARTS HERE **********[/b]
DWORD WINAPI FunkcjaWatku(PVOID pvParam)
{
int g=(int)pvParam;
int argc;
char** argv;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(250,250);
glutInitWindowPosition(100,100);
glutCreateWindow("Hello World");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
[b]// ***MAIN THREAD***[/b]
int main()
{
....some code......
// new thread
DWORD IdWatku;
int x = 6;
if(CreateThread(NULL, 0, FunkcjaWatku, (PVOID)x, 0, &IdWatku)==NULL)
{
printf("Problem z inicjacja watku");
}
else
{
printf("Help uruchomiony.");
}
...additional code.....
}
is there a scheme for creating OpenGL threads? Say something like:
1. include glut
2. OpenGL functions
3. thread declaration
4. main
{
5. new thread
}
?
And so my question is this:
How can I create a new thread which opens a OpenGL window in a console app? It’s kind of important for me in the future as I would like to use a similar window for visualization of data later on.
Thank you for any help you can give.
Rafal Typiak