Hi,
please can someone look on this and let me know what exactly is wrong?
(i need to blit it correctly using alpha channel) Thanks for your help
// i just try tu update some nehe tutorial…
#ifdef WIN32
//#define WIN32_LEAN_AND_MEAN //if i leave this defined here then
something goes wrong
//and i don’t have functions like exit and so…but in full tutorial is it
OK.
//do u know WHY?
#include <windows.h>
#endif
#if defined(APPLE) && defined(MACH)
#include <OpenGL/gl.h> // Header File For The OpenGL32 Library
#include <OpenGL/glu.h> // Header File For The GLu32 Library
#else
#include <GL/gl.h> // Header File For The OpenGL32 Library
#include <GL/glu.h> // Header File For The GLu32 Library
#endif
#include “SDL.h”
#include "SDL_image.h"
float xpos,ypos;
GLuint texture[10];
GLuint raketka;
SDL_Surface *LoadIMG(char *filename)
{
SDL_Surface *image;
image = IMG_Load(filename);
if ( image == NULL ) {
fprintf(stderr, “Unable to load %s: %s\n”, filename,
SDL_GetError());
return(NULL);
}
// i don't care about colors order now.
return(image);
}
// Load Bitmaps And Convert To Textures
void LoadGLTextures(void)
{
// Load Texture
SDL_Surface *image[10];
char buffer[30];
for (int i=0; i<10; i++)
{
sprintf(buffer,“data/field%d.jpg”,i);
image[i] = LoadIMG(buffer);
glGenTextures(1, &texture[i]);
glBindTexture(GL_TEXTURE_2D, texture[i]); // 2d texture
(x and y size)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // scale
linearly when image bigger than texture
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // scale
linearly when image smalled than texture
glTexImage2D(GL_TEXTURE_2D, 0, 3, image[i]->w, image[i]->h, 0,
GL_RGB, GL_UNSIGNED_BYTE, image[i]->pixels);
}
SDL_Surface *rocket;
rocket = LoadIMG(“fighter1.tga”); //yes i am sure that this image
is OK. And is RGBA
glGenTextures(1, &raketka);
glBindTexture(GL_TEXTURE_2D, raketka);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //
scale linearly when image bigger than texture
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); //
scale linearly when image smalled than texture
glTexImage2D(GL_TEXTURE_2D, 0, 4, rocket->w, rocket->h, 0, GL_RGBA,
GL_UNSIGNED_BYTE, rocket->pixels);
};
/* A general OpenGL initialization function. Sets all of the initial
parameters. */
void InitGL(int width, int height)
{
LoadGLTextures();
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
/* The main drawing function. */
void DrawGLScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity(); // Reset The View
// glTranslatef(xpos,ypos,-4.62f);
glTranslatef(0,0,-5.0f);
float xt,yt,zt;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 2; j++)
{
glBindTexture(GL_TEXTURE_2D, texture[2i + j]);
glBegin(GL_QUADS);
xt = -2.0f + j2;
yt = -1.0f + i*2;
glTexCoord2f(0.0f, 1.0f); glVertex3f(xt, yt, 1.0f);
xt = xt + 2.0f;
glTexCoord2f(1.0f, 1.0f); glVertex3f(xt, yt,
1.0f);
yt += 2.0f;
glTexCoord2f(1.0f, 0.0f); glVertex3f(xt, yt,
1.0f);
xt = xt - 2.0f;
glTexCoord2f(0.0f, 0.0f); glVertex3f(xt, yt,
1.0f);
glEnd();
}
}
glDisable(GL_DEPTH_TEST);
// Enables Depth Testing
glEnable(GL_BLEND);
//************************************************************************************
glBlendFunc(GL_ONE,GL_ONE);
//WHAT SHOULD BE HERE???
// i want to blit it using alpha channel (so 100% A means only
source 0% A means only
// dest)
//************************************************************************************
glBindTexture(GL_TEXTURE_2D,raketka);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0,0.3f, 2.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.4f,0.3f, 2.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.4f,0, 2.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(0,0, 2.0f);
glEnd();
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
SDL_GL_SwapBuffers();
}
#define TICK_INTERVAL 30
Uint32 TimeLeft(void)
{
static Uint32 next_time = 0;
Uint32 now;
now = SDL_GetTicks();
if ( next_time <= now ) {
next_time = now+TICK_INTERVAL;
return(0);
}
return(next_time-now);
}
int main(int argc, char **argv)
{
int done;
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, “Unable to initialize SDL: %s\n”, SDL_GetError());
return 1;
}
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
if ( SDL_SetVideoMode(800, 600, 0, SDL_OPENGL) == NULL ) {
fprintf(stderr, “Unable to create OpenGL screen: %s\n”,
SDL_GetError());
SDL_Quit();
exit(2);
}
SDL_WM_SetCaption(“Test”, NULL);
InitGL(800, 600);
done = 0;
xpos = 0.0f;
ypos = 0.0f;
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL);
Uint32 now,before;
now = 0; before = 0;
while ( ! done ) {
DrawGLScene();
SDL_Event event;
while ( SDL_PollEvent(&event) ) {
if ( event.type == SDL_QUIT ) {
done = 1;
}
}
SDL_Delay(TimeLeft());
ypos -= 0.01f;
}
SDL_Quit();
return 1;
}