Re: [Plib-users] Drawing a simple triangle
Brought to you by:
sjbaker
From: Peter P. <pet...@st...> - 2004-03-07 17:26:28
|
Steve Baker <sjb...@ai...> writes: > Peter Poulsen wrote: > > I have tried the program below, but it only shows a black screen. Can > > anybody explain why? The program works if I make direct gl-calls (just > > comment out the first line). > > SSG uses the 'Z-is-up' convention - so I guess your polygon is edge-on. > Also, SSG defaults to perspective rendering - so it'll be near-plane > clipped. Thanks. I have now tried to modify the program, but it still does not work :-) I'm sorry for bothering you with this trivil matter, but if I cannot get that to work, I probably cannot get a "real" program to work. --- ssg_triangle.cc --- #define USE_SSG 1 #include <GL/gl.h> #include <GL/glu.h> #include <plib/ssg.h> #include <SDL/SDL.h> #include <iostream> using namespace std; ssgRoot* scene; #define SCREEN_WIDTH 320 #define SCREEN_HEIGHT 240 #define SCREEN_BPP 24 void init() { int videoFlags; SDL_Surface* surface; if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { fprintf( stderr, "Video initialization failed: %s\n", SDL_GetError( ) ); exit(0); } videoFlags = SDL_OPENGL; videoFlags |= SDL_GL_DOUBLEBUFFER; videoFlags |= SDL_HWPALETTE; videoFlags |= SDL_HWSURFACE; surface = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, videoFlags ); if ( !surface ) { fprintf( stderr, "Video mode set failed: %s\n", SDL_GetError( ) ); exit(0); } #ifdef USE_SSG ssgInit(); glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f ) ; glEnable ( GL_DEPTH_TEST ) ; ssgGetCurrentContext()->setFOV (60.0f, 0.0f); // New ssgGetCurrentContext()->setNearFar(0.1f, 70.0f); // New ssgVertexArray* vertices = new ssgVertexArray; sgVec3 x = { 0.5f, 0.5f , -0.25f}; // Changed sgVec3 y = { -0.5f, 0.5f , -0.25f }; // Changed sgVec3 z = { 0.0f, 0.5f , 0.75f }; // Changed vertices->add(x); vertices->add(y); vertices->add(z); sgVec4 white = { 1.0f, 1.0f, 1.0f, 0.5f }; ssgColourArray* colours = new ssgColourArray; colours->add(white); colours->add(white); colours->add(white); ssgNormalArray* normals = new ssgNormalArray(3); sgVec3 normal = { 0, -1.0f, 0 }; // Changed normals->add(normal); normals->add(normal); normals->add(normal); ssgTexCoordArray* texs = new ssgTexCoordArray(3); sgVec2 tex_vec = {0,0}; texs->add(tex_vec); texs->add(tex_vec); texs->add(tex_vec); ssgVtxTable* n = new ssgVtxTable(GL_TRIANGLES, vertices, normals, texs, colours); ssgTransform* trans = new ssgTransform; trans->addKid(n); scene = new ssgRoot; scene->addKid(trans); #else glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f ) ; glEnable ( GL_DEPTH_TEST ) ; #endif } void update() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ; #ifdef USE_SSG ssgCullAndDraw(scene); #else glLoadIdentity(); glColor3f(1.0f, 1.0f, 1.0f); glBegin(GL_TRIANGLES); glVertex2f(0.5f, -0.25f); glVertex2f(-0.5f, -0.25f); glVertex2f(0.0f, 0.75f); glEnd(); #endif SDL_GL_SwapBuffers( ); } int main(int argc, char *argv[]) { init(); for(unsigned int i = 0; i < 1000; i++) { update(); } return 0; } -- Yours Peter Poulsen |