A triangle and a Quad.

A triangle and a Quad.

glVertex3f,gluPerspective,gluLookAt,glTranslatef...

See version :

Pas de dépendances

Download :

#include <windows.h>
#include <math.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <SDL/SDL.h>

#pragma comment(lib,"sdl.lib")
#pragma comment(lib,"sdlmain.lib")
#pragma comment(lib, "opengl32.lib" )
#pragma comment(lib, "glu32.lib" )

#define XRESOL 400
#define YRESOL 300

int initGL()
{
    // init
    glShadeModel(GL_FLAT);
    glClearColor(0.0f,0.0f,0.0f,0.0f);
    glClearDepth(1.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );  // active l'antialiasing
    // cadrage
    glViewport(0,0,XRESOL,YRESOL);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f,4.0/3.0,1.0f,100.0f);
    return 1;
}

int KeyHit()
{
    SDL_Event e;
    if (SDL_PollEvent(&e))
        if (e.type == SDL_KEYDOWN)
            return 1;
    return 0;
}

int main(int argc, char **argv)
{
    SDL_Surface *surface;
    float e = 0.0f;
    SDL_Init(SDL_INIT_VIDEO);
    surface = SDL_SetVideoMode(XRESOL,YRESOL,32,SDL_HWSURFACE|SDL_OPENGL);
    initGL();
    while(!KeyHit())
    {
        e+=(float)0.005;
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
        glMatrixMode( GL_MODELVIEW );
        glLoadIdentity();
        gluLookAt(0,0,0,0,0,-1,0,1,0);
        glTranslatef(-1.5f,0.0f,-6.0f);
        glBegin( GL_TRIANGLES );
            glVertex3f(  0.0f,  1.0f, e );
            glVertex3f( -1.0f, -1.0f, e );
            glVertex3f(  1.0f, -1.0f, e );
        glEnd( );                          

        glTranslatef( 3.0f, 0.0f, 0.0f );
        glBegin( GL_QUADS );               
            glVertex3f( -1.0f,  1.0f, e );
            glVertex3f(  1.0f,  1.0f, e );
            glVertex3f(  1.0f, -1.0f, e );
            glVertex3f( -1.0f, -1.0f, e );
        glEnd( );                          

        SDL_GL_SwapBuffers( );
    }
    SDL_Quit();
    return 0;
}



Explanations

	No explanations yet.