Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Very odd SDL + OpenGL segfault problem.

loopdelooploopdeloop Member Posts: 2
Hello everyone. I have what seems to me (a beginner) a very strange problem with OpenGL. This is possibly related to SDL or maybe even something else.

I am writing a class for doing pretty basic 2D drawing with hardware acceleration for a game idea. I had something similar working on another system and rather than rebuild it on my new laptop I decided to write again from ground up. The fact I had no probs on the other machine is driving me nuts.
Initially I thought it was usage of glBindTexture() but I have since found that if I try to access ANY variable outside the scope of the drawing methods I get a segmentation fault.

I am using xubuntu 11.10 and SDL 1.2

I initialized SDL with
[code]
SDL_Init (SDL_INIT_EVERYTHING)
display = SDL_SetVideoMode(video_width,video_height,32,SDL_OPENGL )
[/code]
then I have an init() function in my OpenGL class like this,
[code]
bool init(int video_width, int video_height)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glMatrixMode(GL_PROJECTION);
glDisable(GL_DEPTH_TEST);
glLoadIdentity();
glOrtho(0, video_width, video_height, 0, -1, 1);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
if(glGetError() != GL_NO_ERROR)
return false;

return true;
}
[/code]

This works fine with the cout commented out
[code]
void rect_fill(float x1, float y1, float x2, float y2, float r, float g, float b)
{
//std::cout << bl_bitmaps[0]->GL_id << "
";
glColor4f(r,g,b,1.0f);
glBegin(GL_QUADS);
glVertex2f(x1,y1);
glVertex2f(x2,y1);
glVertex2f(x2,y2);
glVertex2f(x1,y2);
glEnd();
}
[/code]
This segfaults
[code]
void rect_fill(float x1, float y1, float x2, float y2, float r, float g, float b)
{
std::cout << bl_bitmaps[0]->GL_id << "
";
glColor4f(r,g,b,1.0f);
glBegin(GL_QUADS);
glVertex2f(x1,y1);
glVertex2f(x2,y1);
glVertex2f(x2,y2);
glVertex2f(x1,y2);
glEnd();
}
[/code]
It doesn't matter what that cout is accessing, I also tested with a simple int within the same class and it segfaults on that too.Can anyone shed a little light on what may be happening here? I would be very grateful.
Sign In or Register to comment.