Jump to content
  • Advertisement
Sign in to follow this  
Concentrate

Help solve this undefined function problem

This topic is 2604 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok disregard the title. The title should be, " HELP showing a square in window ". I am not sure whats the program exactly. This is in C++ , SDL , and OpenGL.

Here is the function call :


OpenGLWindow window;
window.createContext();
window.run();


and here is the run function:


bool BaseWindow::run(){
if(!setupContext()) return false;
gameLoop();
if(!cleanupContext()) return false;
return true;
}

Here is the used setupContext()


bool OpenGLWindow::setupContext()const{
return (*_initFunc)(); //calls the _defaultOpenGLInit function below
}

static bool _defaultOpenGLInit(){
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
return true;
}

Here is the gameLoop() function:


void OpenGLWindow::gameLoop(){
SDL_Event event;
bool isRunning = true;
//start the game loop
while(isRunning){

//check and handle for any events
while(SDL_PollEvent(&event)){
isRunning = _eventHandler(event);
}
//render screen
(*_renderFunc)();
}
}


and the renderFunc:


static bool _defaultOpenGLRenderFunc(){
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
/* render blah */
glBegin( GL_LINES );
glColor3f(1,0,0);
glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
glEnd();
SDL_GL_SwapBuffers();
return true;
}


all I get is a black screen.

Share this post


Link to post
Share on other sites
Advertisement
I guess I fixed it. I had to call


static bool _defaultOpenGLResizeFunc(const OpenGLWindow::uInt w, const OpenGLWindow::uInt h){
//Tell OpenGL how to convert from coordinates to pixel values
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION); //Switch to setting the camera perspective
//Set the camera perspective
glLoadIdentity(); //Reset the camera
gluPerspective( 45.0, //The camera angle
(double)w / (double)h, //The width-to-height ratio
1.0, //The near z clipping coordinate
200.0); //The far z clipping coordinate
return true;
}

before doing any rendering. But every time I resize the window, I get buch of extra crap on the screen. Any idea?

Share this post


Link to post
Share on other sites
Define "a bunch of extra crap". Are you calling this function before or after you've called SDL_SetVideoMode() again? With what values of w/h are you calling it?

Consider posting a minimal example (e.g. a simple main() function) that demonstrates the problem you're having.

Share this post


Link to post
Share on other sites
I'm running under mac. Whenever I resize, the background screen goes black.

As a minimal example :

int main(){
//...init sdl stuff
screen = createContext(600,400,32);
//init opengl stuff

while isRunning
while SDL_PollEvent
case SDL_VIDEORESIZE: screen = createContext(600,400,32)
end while;
render();
end while;
}


the above is psuedo code. Everytime I resize the window manually, The background screen goes black, but the shape is still drawn. I could show you the actual-actual code if you want.

Share this post


Link to post
Share on other sites
Thats because you RECREATE the context, making any loaded textures invalid. You should just resize viewport, IMO. That's my guess. Is this helpful?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!