Results 1 to 3 of 3

Thread: SDL/OpenGL shape rotation problem!

  1. #1
    Junior Member Newbie OhSnapEpicPwnage's Avatar
    Join Date
    Apr 2011
    Location
    Croatia
    Posts
    7

    SDL/OpenGL shape rotation problem!

    Why does this fail?
    Whenever angle is set to 0 shape is visible, but when its increased to 0.1 or higher then the shape dissappears :S.
    Code :
    #include "SDL/SDL.h"
    #include <gl/gl.h>
    #include <gl/glu.h>
    #include <gl\glaux.h>
    void LoopFunc();
     
    SDL_Surface *screen = NULL;
    SDL_Event event;
     
    GLfloat angle= 0.0f;
     
    int main(int argc,char *args[])
    {
        int start;
     
        SDL_Init(SDL_INIT_EVERYTHING);
        screen = SDL_SetVideoMode(800,600,32,SDL_HWSURFACE | SDL_OPENGL);
        glClearColor(0, 0, 0, 0);
        glClearDepth(1.0f);
        glViewport(0, 0, 800, 600);
     
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0, 800, 600, 0, 1, -1);
        glMatrixMode(GL_MODELVIEW);
        glEnable(GL_TEXTURE_2D | GL_DEPTH_TEST);
        glLoadIdentity();
     
     
        while(true)
        {
            start = SDL_GetTicks();
     
            if(SDL_PollEvent(&amp;event))
            {
                if(event.type == SDL_QUIT)
                {
                    return false;
                }
                if(event.type == SDL_KEYDOWN)
                {
                    if(event.key.keysym.sym == SDLK_ESCAPE)
                    {
                        return false;
                    }
                }
            }
     
            LoopFunc();
     
     
            SDL_Flip(screen);
        }
     
        SDL_Quit();
     
        return 0;
    }
     
    void LoopFunc()
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glLoadIdentity();
     
        glRotatef(angle,1.0f,0.0f,0.0f);
        glBegin(GL_TRIANGLES);
            glColor3f(1.0f,0.0f,0.0f);
            glVertex3f(350.0f,100.0f,-1.0f);
            glColor3f(0.0f,1.0f,0.0f);
            glVertex3f(100.0f,400.0f,-1.0f);
            glColor3f(0.0f,0.0f,3.0f);
            glVertex3f(600.0f,400.0f,-1.0f);
        glEnd();
     
        angle+= 0.2f;
     
        SDL_GL_SwapBuffers();
    }
    ~No man deserves punishment for his thoughts.~

  2. #2
    V-man
    Guest

    Re: SDL/OpenGL shape rotation problem!

    glEnable(GL_TEXTURE_2D | GL_DEPTH_TEST);
    is not valid code

    See
    http://www.opengl.org/wiki/Common_Mi...ld_enumerators

    Convert
    glOrtho(0, 800, 600, 0, 1, -1);
    to
    glOrtho(0.0, 800.0, 600.0, 0.0, 1000.0, 1000.0);

  3. #3
    Junior Member Newbie OhSnapEpicPwnage's Avatar
    Join Date
    Apr 2011
    Location
    Croatia
    Posts
    7

    Re: SDL/OpenGL shape rotation problem!

    Thanks man!
    Only that
    Code :
    glOrtho(0.0, 800.0, 600.0, 0.0, 1000.0, 1000.0);
    fails,but works if i do
    Code :
    glOrtho(0.0, 800.0, 600.0, 0.0, 1000.0, -1000.0);
    then it works just fine.
    ~No man deserves punishment for his thoughts.~

Similar Threads

  1. Replies: 1
    Last Post: 07-24-2014, 04:59 PM
  2. OpenGL Rotation/Translation Problem
    By fp13__ in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 04-25-2013, 06:38 PM
  3. Shape rotation issues
    By Khorask in forum OpenGL: Windows
    Replies: 3
    Last Post: 02-18-2011, 02:59 AM
  4. Morph Target/Blend Shape problem
    By Cansin in forum COLLADA
    Replies: 1
    Last Post: 07-11-2010, 05:56 AM
  5. How to find centre of a 2D shape for rotation?
    By jojo555 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-04-2004, 04:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean