|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
OpenGL with Pthreads
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
Kernel Sanders
|
I'm trying to make a multithreaded app that uses OpenGL. For testing purposes I took the Red Book's hello world program and threw it into a second thread. When I run it, I get a plain white box with no contents or titlebar. The program takes 100% CPU time and stops responding after a few seconds.
If I nix the thread and call the gl_main function directly from the primary thread, the program runs as normal. Anybody have an idea what's going on? glutMainLoop does get called, but it does nothing except load the CPU. Here is the code Code:
#include <GLUT/glut.h>
#include <pthread.h>
#include <stdio.h>
int *g_argc;
char **g_argv;
void display(void){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_POLYGON);
glVertex3f(0.25, 0.25, 0.0);
glVertex3f(0.75, 0.25, 0.0);
glVertex3f(0.75, 0.75, 0.0);
glVertex3f(0.25, 0.75, 0.0);
glEnd();
glFlush();
}
void init(void){
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}
void *g_main(void *arg){
int i;
printf("Argc: %dn", *g_argc);
for(i=0; i<*g_argc; i++)
printf("Argv[%d]: %sn", i, g_argv[i]);
glutInit(g_argc, g_argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(250, 250);
glutInitWindowPosition(100, 100);
glutCreateWindow("Hello, world");
init();
glutDisplayFunc(display);
glutMainLoop();
return NULL;
}
int main(int argc, char **argv){
g_argc = &argc; g_argv = argv;
pthread_t thread;
pthread_create(&thread, NULL, &g_main, NULL);
// g_main(NULL);
char c;
printf("Will exit if you enter a charn"); scanf("%c", &c);
}
|
|||||||||||||
|
|
|
|
#2 (permalink) | |||||||||||||
|
Programmer
|
This isn't based off much of anything but you might try creating the window in the main and then updating it in a seperate thread.
__________________
"He attacked everything in life with a mix of extraordinary genius and naive incompetence, and it was often difficult to tell which was which." Douglas Adams
|
|||||||||||||
|
|
|
|
|
#3 (permalink) | |||||||||||||
|
*cough* Stock *cough*
Join Date: Dec 2007
Location: Santa Cruz Mountains
Posts: 404
Rep: 45
![]() Unique Rep: 41
Trader Rating: 5
|
I just sent that code snippet to one of my friends (hope that is OK). He is an OpenGL genius! If he can't figure it out...
__________________
"The computer can't tell you the emotional story. It can give you the exact mathematical design, but what's missing is the eyebrows. "...Frank Zappa... Edit/Delete Message
|
|||||||||||||
|
|
|
|
|
#4 (permalink) | |||||||||||||
|
Kernel Sanders
|
There's still the CPU load and non responsiveness, but I do get a valid window now. Thanks a lot
|
|||||||||||||
|
|
|
|
#5 (permalink) | |||||||||||||
|
Programmer
|
Hmm, well that gets me good and curious... If I remember I'll mess with it when I get home from work.
__________________
"He attacked everything in life with a mix of extraordinary genius and naive incompetence, and it was often difficult to tell which was which." Douglas Adams
|
|||||||||||||
|
|
|
|
|
#6 (permalink) | ||||||||||||||
|
Kernel Sanders
|
Wiki has the answer
Quote:
![]() I'm probably going to nix GLUT and go with GLX. Now I just have to find a good reference
|
||||||||||||||
|
|
|
|
#7 (permalink) | |||||||||||||
|
Programmer
|
Ahh, that explains it. I did my openGL stuff in Qt for my schoolwork, haven't messed with it since I graduated but that's good to know
![]()
__________________
"He attacked everything in life with a mix of extraordinary genius and naive incompetence, and it was often difficult to tell which was which." Douglas Adams
|
|||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|