Simple program won't work...
/*
Please try this: It gives an error at glBindTextures in the DrawFace procedure... Why? When i use the stack for ''textures'' it works just fine... When trying make a Marty.bmp and a Marty2.bmp in the same dir.
Marty
*/
#include <gl\glut.h>
#include <gl\glaux.h>
#include <stdio.h>
GLuint * textures;
GLfloat anglex, angley = 0;
AUX_RGBImageRec *LoadBMP(char *Filename)
{
FILE *File=NULL;
if (!Filename){return NULL;}
File=fopen(Filename,"r");
if (File){fclose(File); return auxDIBImageLoad(Filename);}
return NULL;
}
void LoadGLTexture(char *filename, GLuint num, GLuint * texture)
{
AUX_RGBImageRec * TextureImage[1];
memset(TextureImage,0,sizeof(void *)*1);
TextureImage[0]=LoadBMP(filename);
glGenTextures(1, &texture[num]);
glBindTexture(GL_TEXTURE_2D, texture[num]);
glTexImage2D( GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0,
GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
free(TextureImage[0]->data);
free(TextureImage[0]);
}
void DrawFace()
{
glTranslatef(0,0,-5);
glRotatef(anglex,1,0,0);
glRotatef(angley,0,1,0);
glBindTexture(GL_TEXTURE_2D, textures[1]);
glBegin(GL_TRIANGLE_STRIP);
//rechtsboven
glTexCoord2f(1.0f, 1.0f);
glVertex3f(1,1,0);
//rechtsonder
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-1,1,0);
//linksboven
glTexCoord2f(1.0f, 0.0f);
glVertex3f(1,-1,0);
//linksonder
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1,-1,0);
glEnd();
glBindTexture(GL_TEXTURE_2D, textures[0]);
glBegin(GL_TRIANGLE_STRIP);
//rechtsboven
glTexCoord2f(1.0f, 1.0f);
glVertex3f(1,1,0);
//rechtsonder
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-1,1,0);
//linksboven
glTexCoord2f(1.0f, 0.0f);
glVertex3f(1,-1,0);
//linksonder
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1,-1,0);
glEnd();
}
void init()
{
GLuint * textures = new GLuint[2];
LoadGLTexture("Marty.bmp", 0, textures);
LoadGLTexture("Marty2.bmp", 1, textures);
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glEnable(GL_BLEND);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glClearColor(0,0,0,0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, 1.0, 1.0, 1000.0);
glMatrixMode(GL_MODELVIEW);
glColor4f(1.0f,1.0f,1.0f,0.5f);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
}
void Display()
{
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
DrawFace();
glutSwapBuffers();
}
void Idle()
{
anglex++;
angley++;
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutCreateWindow("Multiple Textures Test");
init();
glutIdleFunc(Idle);
glutDisplayFunc(Display);
glutMainLoop();
return 0;
}
_____ /____ /|| | || MtY | ||_____|/Marty
Try changing
GLuint * textures;
into
GLuint * textures[2];
It''s early and that''s all I can think of, maybe later I can think more clearly.
Later,
Michael Bartman
GLuint * textures;
into
GLuint * textures[2];
It''s early and that''s all I can think of, maybe later I can think more clearly.
Later,
Michael Bartman

Michael BartmanLead ProgrammerDark Omen Studios
nope, that isn''t it... It works now, I just don''t use the pointer anymore...
Thanx anyways, Marty
Thanx anyways, Marty
_____ /____ /|| | || MtY | ||_____|/Marty
Should GL_TEXTURE_COORD_ARRAY''s be in the same order as the vertexes of the indexes, when I use glDrawElements? My program gives acces violation, so I guess it''s the number of indexes... When i divide the number by 2, it doesn''t give an error (because it doesn''t go out of range for all the arrays), but it shows only some pixels of texture... What''s wrong? I''ll try the index numbers next, i''ll post when the problem is fixed.
Marty
Marty
_____ /____ /|| | || MtY | ||_____|/Marty
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement