Usenet.com

www.Usenet.com

Group Index

Comp Thread Archive from Usenet.com

<-- __Chronological__ --> <-- __Thread__ -->

Flickering!!!!



I'm writing a little test program using OpenGL and SDL 1.2.5 on SuSE Linux
8,2. My output is always flickering. Sometimes the triangles are rendered
and sometimes they arent. Can somebody help me?

I'm sorry about my bad English.

Listing:

#include <iostream>
#include <cstdlib>
#include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>

using namespace std;

#define DO_FULLSCREEN false

bool g_gameRunning= false;

void renderScene();
void init();

int main(int argc, char *argv[])
{
  g_gameRunning= true;
  const SDL_VideoInfo* info = NULL;
  //bits per pixel
  int bpp= 0;
  // Flags we will pass into SDL_SetVideoMode.
  int flags = 0;

  //Init the SDL-Video subsystem
  if (SDL_Init(SDL_INIT_VIDEO) != 0)
  {
    //Some error occured!!
    cout << "SDL_Init(SDL_INIT_VIDEO) failed." << endl;
    return 0;
  }
  /* Let's get some video information. */
  info = SDL_GetVideoInfo( );
  if( !info )
  {
    cout << "SDL_GetVideoInfo() failed." << endl;
    return 0;
  }
  // Set some attributes. We want R5_G5_B5
  SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
  SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
  SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );  

  //Depthbuffering with 16bit
  SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );

  //Activate Doublebuffering
  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  bpp= info->vfmt->BitsPerPixel;
  if (DO_FULLSCREEN)
    flags= SDL_OPENGL | SDL_FULLSCREEN;
  else
    flags= SDL_OPENGL;

  if (SDL_SetVideoMode(800, 600, 16, flags) == 0 )
  {
    cout << "SDL_SetVideoMode() failed." << endl;
    return 0;
  }
  //-----------------------------------------

  //-----------------------------------------
  init();
  //-----------------------------------------


  //-----------------------------------------
  while (g_gameRunning)
  {
    renderScene();
  }
  //-----------------------------------------

  return EXIT_SUCCESS;
}
}

void renderScene()
{
  static float angle= 0.0;
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glPushMatrix();
    glTranslatef(0.0, 0.0, -1.0);
    glRotatef(angle++, 0.0, 1.0, 0.0);
    glBegin(GL_TRIANGLES);
       glNormal3f(0.0, 1.0, 0.0);
       glVertex3f(-0.5000, -0.5000, 0.0000);//0
       glVertex3f(-0.5000, 0.5000, 0.0000); //2
       glVertex3f(0.5000, 0.5000, 0.0000);  //3
       
       glNormal3f(0.0, 0.0, 1.0);
       glVertex3f(0.5000, 0.5000, 0.0000);  //3
       glVertex3f(0.5000, -0.5000, 0.0000); //1
       glVertex3f(-0.5000, -0.5000, 0.0000);//0

       glNormal3f(1.0, 0.0, 0.0);
       glVertex3f(0.5000, -0.5000, 1.0000); //4
       glVertex3f(0.5000, -0.5000, 1.0000); //5
       glVertex3f(0.5000, 0.5000, 1.0000);  //7

       glNormal3f(1.0, 0.0, 0.0);       
       glVertex3f(0.5000, 0.5000, 1.0000);  //7
       glVertex3f(-0.5000, 0.5000, 1.0000); //6
       glVertex3f(0.5000, -0.5000, 1.0000); //5
    glEnd();
  glPopMatrix();
  glFlush();
  glFinish();
  SDL_GL_SwapBuffers();
}

void init()
{
  glClearColor(0.0, 0.0, 1.0, 1.0);
  glClearDepth(1.0);
  glShadeModel(GL_SMOOTH);
  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  glEnable(GL_DEPTH_TEST);
  glDisable(GL_CULL_FACE);
  glDisable(GL_TEXTURE_2D);
  float lightpos[]= {1.0, 1.0, 1.0, 0.0};
  float lightdiffuse[]= {0.5, 0.5, 0.5, 1.0};
  glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, lightdiffuse);
  glLightfv(GL_LIGHT0, GL_AMBIENT, lightdiffuse);
  glLightfv(GL_LIGHT0, GL_SPECULAR, lightdiffuse);

  glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.1);
  float matambient[]= {0.8, 0.1, 0.4, 1.0};
  glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, matambient);
  glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0, 1.33333, 0.0, 100.0);
  glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();  
}



<-- __Chronological__ --> <-- __Thread__ -->


Usenet.com



Please check out one of the premium Usenet Newsgroup Service Providers below for access to Usenet.