witam, mam problem z dodaniem tekstury, korzystałem z tutoriala NeHe, wywala mi taki błąd podczas kompilowania: openglProg8.cpp: In function ‘void loadGLTextures()’:
openglProg8.cpp:120:41: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
openglProg8.cpp:125:31: error: invalid conversion from ‘int*’ to ‘GLuint* {aka unsigned int*}’ [-fpermissive]
In file included from /usr/include/GL/freeglut_std.h:120:0,
from /usr/include/GL/freeglut.h:17,
from openglProg8.cpp:1:
/usr/include/GL/gl.h:1335:23: error: initializing argument 2 of ‘void glGenTextures(GLsizei, GLuint*)’ [-fpermissive]
pierwsza informacja to warning że funkcja jest przestarzała, mam problem z errorem, robiłem tak jak w tym tutorialu i [błąd ortograficzny] jak rozwiązać ten problem z tą konwersją typów w funkcji glGenTextures(GLsizei, GLuint*), o to kod programu, chciałem na ścianę nałożyć teksturę i w ten sposób zrobić sześcian, program wymaga przeróbki bo podstawą był sześcian zrobiony ze ścian które są w różnych kolorach.
#include
#include
#include
/*autor programu: marcin kaszuba
* program wyswietla szescian z zachowaniem proporcji i obraca nim za pomoca klawiatury
*wokół osi x i y oraz obraca zapomoca funkcji anim wokol osi z
* obsluga klawiatury i tryb gamemode
*ladowanie tekstury 2d
*kompilacja: g++ openglProg8.cpp -o openglProg8 -lGL -lGLU -lglut
*/
const int width = 640;
const int height = 480;
const float a = 1.0;
float fovy = 45.0, aspect = 1.0, near_ = 0.1, far_ = 10.0;//parametry dla gluPerspective();
const float count = 0.25;
float rotateX = 0.0;
float rotateY = 0.0;
const float deltaAlfa = (float)0.1;
float alfa = 0.1;
int texture[1]; //przechowywanie jednej tekstury
struct image{
unsigned long sizeX;
unsigned long sizeY;
char *data;
};
typedef struct image image;
int imageLoad(char *filename, image *image){
FILE *file;
unsigned long size;//rozmiar pliku w bajtach
unsigned long i;//typ licznika
unsigned short int planes;//numer plaszczyzny obrazka(musi byc 1)
unsigned short int bpp;//przechowywanie tymczasowego koloru po konwersji bgr-rgb
char temp;
//sprawdzanie czy plik istnieje
if((file = fopen(filename, "rb")) == NULL){
printf("plik nie istnieje : %s\n", filename);
return 0;
}
//ustawiamy pozycje wskaznika w pliku
fseek(file, 18, SEEK_CUR);
//czytamy wysokosc
if((i = fread(&image->sizeX, 4, 1, file)) != 1){
printf("blad czytania wysokosci z pliku: %s\n", filename);
return 0;
}
printf("wysokosc pliku %s: %lu\n", filename, image->sizeX);
//czytamy szerokosc
if((i = fread(&image->sizeY, 4, 1, file)) != 1){
printf("blad czytania szerokosci z pliku: %s\n", filename);
return 0;
}
printf("szerokosc pliku %s: %lu\n", filename, image->sizeY);
//liczymy rozmiar(zakladamy 24 bity lub 3 bajty na pixel)
size = image->sizeX * image->sizeY * 3;
//kopiujemy 1 element pliku do tablicy
if((fread(&planes, 2, 1, file)) != 1){
printf("blad czytania plaszczyzny pliku %s.\n", filename);
return 0;
}
if(planes != 1){
printf("plaszczyzna z pliku %s nie jest 1: %u\n", filename, planes);
return 0;
}
//czytanie bpp
if((i = fread(&bpp, 2, 1, file)) != 1){
printf("blad czytania bpp z pliku %s.\n", filename);
return 0;
}
if(bpp != 24){
printf("Bpp z pliku %s nie jest 24: %u\n", filename, bpp);
return 0;
}
// seek past the rest of the bitmap header.
fseek(file, 24, SEEK_CUR);
//czytanie danych
image->data = (char *) malloc(size);
if(image->data == NULL){
printf("blad allokacji pamieci z poprawionych kolorow danych obrazka\n");
return 0;
}
if((i = fread(image->data, size, 1, file)) != 1){
printf("blad czytania danych obrazka z pliku %s.\n", filename);
return 0;
}
for(i=0;i rgb)
temp = image->data[i];
image->data[i] = image->data[i+2];
image->data[i+2] = temp;
}
// koniec
return 1;
}
//ladowanie bitmapy i konwersja do tekstury
void loadGLTextures(){
//ladowanie tekstury
image *image1;
//allokacja przestrzeni dla tekstury
image1 = (image *) malloc(sizeof(image));
if(image1 == NULL){
printf("blad allokacji pamieci dla obrazka\n");
exit(0);
}
if(!imageLoad("Data/text1.bmp", image1)){
exit(1);
}
//tworzenie tekstury
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]); // 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
// 2d texture, level of detail 0 (normal), 3 components (red, green, blue), x size from image, y size from image,
// border 0 (normal), rgb color data, unsigned byte data, and finally the data itself.
glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->sizeX, image1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image1->data);
}
void display();
void uklad();
void odrysuj(int width, int height);
void keyboard(int key, int x, int y);
void init();
void anim();
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
//glutInitWindowSize(width, height);
//glutInitWindowPosition(100,100);
//glutCreateWindow("Scena testowa");
glutGameModeString("1366x768:32");
if(glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)){
glutEnterGameMode();
} else {
printf("The select mode is not available\n");
exit(1);
}
init();
glutMainLoop();
return 0;
}
void uklad(){
glBegin(GL_LINES);
glColor3f(0.0, 1.0, 0.0); //zielona os X
glVertex3f(-8.0, 0.0, 0.0);
glVertex3f( 8.0, 0.0, 0.0);
glColor3f(0.0, 0.0, 1.0); // niebieska os Y
glVertex3f(0.0, -8.0, 0.0);
glVertex3f(0.0, 8.0, 0.0);
glColor3f(1.0, 0.0, 0.0); // czerwona os Z
glVertex3f(0.0, 0.0, -8.0);
glVertex3f(0.0, 0.0, 8.0);
glEnd();
}
void sciana(){
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-a / 2, 0.0, a / 2);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(-a / 2, 0.0, -a / 2);
glTexCoord2f(1.0f, 1.0f);
glVertex3f( a / 2, 0.0, -a / 2);
glTexCoord2f(0.0f, 1.0f);
glVertex3f( a / 2, 0.0, a / 2);
glEnd();
}
void szescian(){
//dolna sciana
glPushMatrix();
glTranslatef(0.0, -a /2, 0.0);
glColor3f(0.0, 0.0, 1.0);
sciana();
glPopMatrix();
//gorna sciana
glPushMatrix();
glTranslatef(0.0, a /2, 0.0);
glColor3f(0.0, 1.0, 1.0);
sciana();
glPopMatrix();
//lewa sciana
glPushMatrix();
glRotatef(90.0, 0.0, 0.0, 1.0);
glTranslatef(0.0, a /2, 0.0);
glColor3f(0.0, 1.0, 0.0);
sciana();
glPopMatrix();
//prawa sciana
glPushMatrix();
glRotatef(90.0, 0.0, 0.0, 1.0);
glTranslatef(0.0, -a /2, 0.0);
glColor3f(1.0, 1.0, 0.0);
sciana();
glPopMatrix();
//tylna sciana
glPushMatrix();
glRotatef(90.0, -1.0, 0.0, 0.0);
glTranslatef(0.0, a /2, 0.0);
glColor3f(1.0, 0.0, 0.0);
sciana();
glPopMatrix();
//przednia sciana
glPushMatrix();
glRotatef(90.0f, -1.0f, 0.0f, 0.0f);
glTranslatef(0.0, -a /2, 0.0);
glColor3f(0.4f, 1.0f, 0.0f);
sciana();
glPopMatrix();
}
void init(){
loadGLTextures(); // Load The Texture(s)
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glClearColor(0.0,0.0,0.0,1.0);
glClearDepth(1.0);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);//wlacznie algorytmu zasłaniania
glShadeModel(GL_SMOOTH);
glutDisplayFunc(display);
glutIdleFunc(anim);
glutReshapeFunc(odrysuj);
glutSpecialFunc(keyboard);
}
void keyboard(int key, int x, int y){
switch(key){
case GLUT_KEY_F1:
glutLeaveGameMode();
break;
case GLUT_KEY_LEFT://obrot w lewo
rotateY-=count;
glutPostRedisplay();
break;
case GLUT_KEY_RIGHT://obrot w prawo
rotateY+=count;
glutPostRedisplay();
break;
case GLUT_KEY_UP://obrot w gore
rotateX-=count;
glutPostRedisplay();
break;
case GLUT_KEY_DOWN://obrot w dol
rotateX+=count;
glutPostRedisplay();
break;
default:
break;
}
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);//"czyszczenie" tła okna i bufora głębokosci
glLoadIdentity();
uklad();
glRotatef(rotateX, 1.0, 0.0, 0.0);
glRotatef(rotateY, 0.0, 1.0, 0.0);
glRotatef(alfa, 0.0, 0.0, 1.0);
glBindTexture(GL_TEXTURE_2D, texture[0]);
szescian();
glFlush();
glutSwapBuffers();
}
void odrysuj(int width, int height){
float h = float(height), w = float(width);
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fovy, w/h, near_, far_);
gluLookAt(2.0,2.0,2.0, 0.0,0.0,0.0, 0.0,1.0,0.0);//obserwator
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void anim(){
alfa+=deltaAlfa;
glutPostRedisplay();
}