VPN termux about China.net

teksture opengl + SDL

 /* to load bmp in this part  download file abb.bmp or create your's bmp
in GIMP program or another profesional graphic studio if you use GIMP then export to bmp format. Can't use just paint and save as.. bmp. To load in opengl use GIMP */

 #include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <SDL/SDL.h>

SDL_Surface* surface;
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
#define SCREEN_BPP 255
#define FALSE 0
#define TRUE 1
GLuint texture[1];
void wyswietlanie(void)
{
 
    glClear(GL_COLOR_BUFFER_BIT);
 
 
 
 
    glBegin(GL_POLYGON);
     
        glTexCoord2f(1.0f,1.0f);

        glVertex2f(-0.9,-0.9);

        glTexCoord2f(1.0f, 0.0f);

        glVertex2f(-0.9, 0.9);

        glTexCoord2i(0.0f,0.0f);

        glVertex2f( 0.9,0.9);

        glTexCoord2i(0.0f, 1.0f);

        glVertex2f( 0.9,-0.9);

     
    glEnd();
  
    glFlush();
}

void skalowanie(int s, int w)
{
 
 
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();



}
namespace SDL
{

int LoadGLTextures( )
{
    /* Status indicator */
    int Status = FALSE;

    /* Create storage space for the texture */
    SDL_Surface *TextureImage;

    /* Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit */
    if ( ( TextureImage= SDL_LoadBMP( "abb.bmp" ) ) )
        {

        /* Set the status to true */
        Status = TRUE;
       
        /* Create The Texture */
        glGenTextures( 1, &texture[0] );

        /* Typical Texture Generation Using Data From The Bitmap */
        glBindTexture( GL_TEXTURE_2D, texture[0] );

        /* if you don't use nvidia try GL_RGB */

        glTexImage2D( GL_TEXTURE_2D, 0, 3, TextureImage->w,
              TextureImage->h, 0, GL_BGR,
              GL_UNSIGNED_BYTE, TextureImage->pixels );
        glGetError();

        /* Linear Filtering */
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

    glEnable(GL_TEXTURE_2D);
        }

    /* Free up any memory we may have used */
    if ( TextureImage)
        SDL_FreeSurface( TextureImage );

    return Status;
}
};
int main(int argc,char **argv)                   //kopjuj wklej p.

{

    glutInit(&argc,argv);

  
    glutInitDisplayMode(GLUT_RGBA);
  
    glutInitWindowSize(600,800);
  
    glutInitWindowPosition(50,50);
  
    glutCreateWindow("NakÅ‚adanie tekstur");

 
    glClearColor(0,0,0,0);
  
    SDL::LoadGLTextures();

  
    glutDisplayFunc(wyswietlanie);
    glutReshapeFunc(skalowanie);

 
    glutMainLoop();
}

No comments:

Post a Comment