Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

Thread: MD2 comes out sideways

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2008
    Posts
    9

    MD2 comes out sideways

    So, I'm working with SDL and OpenGL, and I know SDL makes textures upside-down, but what's really strange is that for some reason I imported an MD2 model into my program, using some code from a tutorial that used Windows code (rather than SDL), and well.... the thing is rendering sideways. @_@

    Is it just something that SDL does? If so, then does anyone know how to fix the problem? And if not, then that clues me that it's possibly something I did wrong...

  2. #2
    Senior Member OpenGL Pro sqrt[-1]'s Avatar
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    1,007

    Re: MD2 comes out sideways

    This is typically caused by different orientation systems of what is "up".

    In some applications "y" is up and in others, "z" is up. Try flipping the y and z values and see if your problem goes away.

    (You may also have to flip face winding and fix normals)

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2008
    Posts
    9

    Re: MD2 comes out sideways

    Okay, now I'm just having weird problems with rendering them in the SDL/OpenGL combo.

    So I'm working with an OpenGL tutorial (actually, a book, but whatever) that explains how to open MD2 files in OpenGL with Win32 code, but I'm converting the project to work with SDL since I prefer it to that Win32 stuff. So I successfully converted everything, and everything seemed to be working correctly up close...



    But then, as the camera gets further from the models, things start to mess up... some of the surfaces start to disappear. I don't know why, since the same OpenGL code works fine with win32 rather than SDL. So I'm wondering if there's something special I have to do in order to keep this from happening.

    Here, you can see part of their faces and legs have appeared to turned black at this distance:


    And in this picture, their faces and front of their bodies have disappeared for no real reason:



    I also noticed that at distances, there's a weird problem with anti-aliasing and jagged lines at a distance... surely that's not normal:


    I had the same problem when rendering a landscape a while back, too... check out the jaggies here (this with OpenGL anti-aliasing turned on):



    I just know there's gotta be something I must not setting up correctly. All this stuff is really bizarre... remember, the Win32 version of the model program works correctly. So I don't get why it has problems in SDL...

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: MD2 comes out sideways

    Looks like zfighting.
    Maybe the SDL version does not query a 24bits zbuffer, and you end up with onlyt 16 bits of depth precision.
    How do you init your GL context and window ?

  5. #5
    Senior Member OpenGL Pro sqrt[-1]'s Avatar
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    1,007

    Re: MD2 comes out sideways

    I would also say the near plane is too close or the far plane is too far away. What are your settings to glFrustum() ?

  6. #6
    Junior Member Newbie
    Join Date
    Feb 2008
    Posts
    9

    Re: MD2 comes out sideways

    Quote Originally Posted by ZbuffeR
    Looks like zfighting.
    Maybe the SDL version does not query a 24bits zbuffer, and you end up with onlyt 16 bits of depth precision.
    How do you init your GL context and window ?
    That doesn't sound like it. But, here's the code anyway:
    Code :
       SDL_Init(SDL_INIT_EVERYTHING);
     
    	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
    	SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
    	SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
    	SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE,8 );
    	SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32 );
     
     
    	SDL_Surface* drawContext;
    	Uint32 flags;
     
    	int width = 800, height = 600;
     
    	flags = SDL_OPENGL | SDL_HWSURFACE | SDL_GL_ACCELERATED_VISUAL;
    	drawContext = SDL_SetVideoMode(width, height, 0, flags);
     
     
    	glViewport(0,0,width,height);	
    	glMatrixMode(GL_PROJECTION);					
    	glLoadIdentity();	
    gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,500.0f);
     
     
    	glMatrixMode(GL_MODELVIEW);		
    	glLoadIdentity();	
    	glEnable(GL_TEXTURE_2D);	
     
    	glBlendFunc(GL_SRC_ALPHA,GL_ONE);
    	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    	glClearDepth(10.0);	
    	glEnable(GL_DEPTH_TEST);	
    	glDepthFunc(GL_LESS);	
    	glShadeModel(GL_SMOOTH);
    	glEnable(GL_CULL_FACE);
    	glFrontFace(GL_CCW);
    	glEnable(GL_LINE_SMOOTH);
    	glEnable(GL_POLYGON_SMOOTH);
    	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
    	glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);


    Quote Originally Posted by sqrt[-1
    ]I would also say the near plane is too close or the far plane is too far away. What are your settings to glFrustum() ?
    glFrustrum...? Actually, I've never used that before, but I have used gluPerspective though. That's similar I suppose.

    Wait, I just looked at the tutorial and I notice that for their gluPerspective() they have set up, they set the first parameter "fovy" as 54.0f... whereas I'm using 45.0f... so I put that number in and sure enough, it's working better now.

    Hmm... gosh, such a newbie at this. xP So anyway, would I need to change the fovy for a different window resolution then?

  7. #7
    Advanced Member Frequent Contributor
    Join Date
    Apr 2004
    Posts
    999

    Re: MD2 comes out sideways

    The last 2 parameters of gluPerspective will be of more interest to you in this case. If the models start disappearing when moving to close your near plane is probably too far away. If they start disappearing when zooming out, your far plane is probably too close. Best way would be too dynamically calculate the near and far plane values based on a bounding box of your scene.

  8. #8
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: MD2 comes out sideways

    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
    Change this ugly 16bits zbuffer to 24bits batman, quick !
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);

  9. #9
    Junior Member Newbie
    Join Date
    Feb 2008
    Posts
    9

    Re: MD2 comes out sideways

    Quote Originally Posted by -NiCo-
    The last 2 parameters of gluPerspective will be of more interest to you in this case. If the models start disappearing when moving to close your near plane is probably too far away. If they start disappearing when zooming out, your far plane is probably too close. Best way would be too dynamically calculate the near and far plane values based on a bounding box of your scene.
    Well, I changed the first parameter, fovy, to "54.0f" as I said... and that problem's gone away. I don't know why, though.

    Should I be calculating the fovy value based on the resolution of the window/screen? Like, if someone were to change the resolution or switch to fullscreen mode, does it have to be given a new value to still render correctly?

    Quote Originally Posted by ZbuffeR
    Change this ugly 16bits zbuffer to 24bits batman, quick !
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
    How did you know my secret identity?! O_O

    Alright, changed it. =P

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •