#include "SDL/SDL.h"
#include "SDL_image.h"
#include "SDL/SDL_opengl.h"
GLuint get_texture(void)
{
SDL_Surface * surface = IMG_Load("image1.png");
SDL_Surface *tempt = SDL_CreateRGBSurface(SDL_SWSURFACE, surface->w, surface->h, 32,
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff
#else
0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000
#endif
);
SDL_BlitSurface(surface, NULL,tempt, NULL);
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tempt->w, tempt->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, tempt->pixels);
SDL_FreeSurface(tempt);
SDL_FreeSurface(surface);
return texture;
}
int main( int argc , char ** argv )
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);
glClearColor(0, 0, 0, 0);
glViewport(0, 0, 640, 480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 640, 480, 0, 1, -1);
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLuint id = get_texture();
glBindTexture(GL_TEXTURE_2D,id);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
GLfloat vertices [] = {
//first quad
0,16,0,
0,0,0,
16,0,0,
16,16,0,
//second quad
50,66,0,
50,50,0,
66,50,0,
66,66,0
};
GLubyte indices [] = {
//first indice
0,1,2,
0,2,3,
//second
4,5,6,
4,6,7
};
GLfloat texvertices [] = {
//first quad
0,.5,
0,0,
.5,0,
.5,.5,
//second quad
.5,1,
.5,.5,
1,.5,
1,1
};
glTexCoordPointer(2, GL_FLOAT,0, texvertices);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_BYTE, indices);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
SDL_GL_SwapBuffers();
SDL_Delay(9000);
return 0;
}
Edited by BeginGamer, 03 July 2012 - 11:56 AM.






