Jump to content
  • Advertisement
Sign in to follow this  

Help solve this undefined function problem

This topic is 2778 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;

and here is the run function:

bool BaseWindow::run(){
if(!setupContext()) return false;
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

//check and handle for any events
isRunning = _eventHandler(event);
//render screen

and the renderFunc:

static bool _defaultOpenGLRenderFunc(){
glMatrixMode( GL_MODELVIEW );
/* render blah */
glBegin( GL_LINES );
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
return true;

all I get is a black screen.

Share this post

Link to post
Share on other sites
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;
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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!