Sampeorna
12-06-2003, 02:36 PM
I am trying to add texture to a glutSolidDodecahedron. Currently experiencing and access violation in the glTexImage2D. I think I am either not reading the bitmaps in correctly or perhaps they have to be translated somehow instead of sent directly to the image pointers...
System information:
Windows 2000 Prof
Visual C++ 6.0
This is an addition to existing code that works correctly. In other words I know all the OpenGL is properly configured with the C++ IDE.
Here is the relavent code
#include <GL/glut.h>
#include <gl\glaux.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
GLUquadricObj *p;
AUX_RGBImageRec *Img[12];
unsigned int ImgText[12];
void display() {
p = gluNewQuadric();
gluQuadricNormals(p, GLU_SMOOTH);
gluQuadricTexture(p, GL_TRUE);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glOrtho(-20,20,-20,20,-20,20);
...
glTranslatef(0,0,-2.75);
glBindTexture(GL_TEXTURE_2D, ImgText[3]);
glutSolidDodecahedron();
...
glutSwapBuffers();
glFlush();
}
void getImage()
{
char *Names[12];
Names[0]="Img/back.bmp";
Names[1]="Img/blue.bmp";
Names[2]="Img/Borg.bmp";
Names[3]="Img/Carpet.bmp";
Names[4]="Img/goldscales.bmp";
Names[5]="Img/Grass.bmp";
Names[6]="Img/Grass2.bmp";
Names[7]="Img/Rock.bmp";
Names[8]="Img/Skin.bmp";
Names[9]="Img/Sky.bmp";
Names[10]="Img/water.bmp";
Names[11]="Img/White.bmp";
Names[12]="Img/Wood.bmp";
for (int i = 0;i<13;i++) {
Img[i] = auxDIBImageLoad(Names[i]);
glGenTextures(13, &ImgText[2]);
glBindTexture(GL_TEXTURE_2D, ImgText[i]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
//ERROR OCCURS HERE --->
glTexImage2D(GL_TEXTURE_2D, 0, 3, Img[i]->sizeX, Img[i]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, Img[i]->data);
}
}
void init() {
glClearColor(0.0,0.0,0.0,0.0);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
getImage();
}
I have tested to make sure it wasn't an array index out of bounds.
The debug information looks like this:
- Img[i] 0x0000000b
sizeX CXX0030: Error: expression cannot be evaluated
sizeY CXX0030: Error: expression cannot be evaluated
data CXX0030: Error: expression cannot be evaluated
System information:
Windows 2000 Prof
Visual C++ 6.0
This is an addition to existing code that works correctly. In other words I know all the OpenGL is properly configured with the C++ IDE.
Here is the relavent code
#include <GL/glut.h>
#include <gl\glaux.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
GLUquadricObj *p;
AUX_RGBImageRec *Img[12];
unsigned int ImgText[12];
void display() {
p = gluNewQuadric();
gluQuadricNormals(p, GLU_SMOOTH);
gluQuadricTexture(p, GL_TRUE);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glOrtho(-20,20,-20,20,-20,20);
...
glTranslatef(0,0,-2.75);
glBindTexture(GL_TEXTURE_2D, ImgText[3]);
glutSolidDodecahedron();
...
glutSwapBuffers();
glFlush();
}
void getImage()
{
char *Names[12];
Names[0]="Img/back.bmp";
Names[1]="Img/blue.bmp";
Names[2]="Img/Borg.bmp";
Names[3]="Img/Carpet.bmp";
Names[4]="Img/goldscales.bmp";
Names[5]="Img/Grass.bmp";
Names[6]="Img/Grass2.bmp";
Names[7]="Img/Rock.bmp";
Names[8]="Img/Skin.bmp";
Names[9]="Img/Sky.bmp";
Names[10]="Img/water.bmp";
Names[11]="Img/White.bmp";
Names[12]="Img/Wood.bmp";
for (int i = 0;i<13;i++) {
Img[i] = auxDIBImageLoad(Names[i]);
glGenTextures(13, &ImgText[2]);
glBindTexture(GL_TEXTURE_2D, ImgText[i]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
//ERROR OCCURS HERE --->
glTexImage2D(GL_TEXTURE_2D, 0, 3, Img[i]->sizeX, Img[i]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, Img[i]->data);
}
}
void init() {
glClearColor(0.0,0.0,0.0,0.0);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
getImage();
}
I have tested to make sure it wasn't an array index out of bounds.
The debug information looks like this:
- Img[i] 0x0000000b
sizeX CXX0030: Error: expression cannot be evaluated
sizeY CXX0030: Error: expression cannot be evaluated
data CXX0030: Error: expression cannot be evaluated