Textur laden und anzeigen
-
Hallo,
sitze immer noch an meinem Punkte-Malprogramm.
Wollte jetzt ein Bild als Textur laden mit Hilfe von DevIL, aber das haut nicht so hin. Die Textur wird nicht im Fenster angezeigt.
Alles was sich mit dem laden verschiedener Bilder ändert, sind die Farben der Punkte die ich setzen kann.
Hier is einfach mal mein Code. Vielleicht hat ja jemand eine rettende Idee.#include <iostream> #include <vector> #include <stdlib.h> #include <GL/glut.h> #include <fstream> //#include <gl/glui.h> using namespace std; #include <windows.h> #include <GL/gl.h> #include <GL/glu.h> #include <IL/il.h> //DevIL ILuint DevILID; // Textur ID für DevIL GLuint OpenGLID; // Textur ID für OpenGL int width = 400; int height = 400; int newheight; //newheight if windowsize changes //type for x and y coordinates typedef struct { int x; int y; }xyCoordinates; //stores coordinates of type xyCoordinates vector<xyCoordinates>clickCoordinates; int x,y; //reshape function void reshape(int width, int height) { glViewport(0, 0,(GLsizei) width, (GLsizei) height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, width, 0, height, 1, -1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); newheight = height; } //display function void display (void) { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POINTS); glColor3f(1.0,1.0,1.0); glutReshapeFunc(reshape); for (int i=0; i<clickCoordinates.size();++i) glVertex2f(clickCoordinates[i].x, newheight - clickCoordinates[i].y); glEnd(); glFlush(); } //mouse function void mouse (int button, int state, int x, int y) { if (button == GLUT_LEFT_BUTTON &&state == GLUT_DOWN) { glVertex2i(x,y); xyCoordinates temp; temp.x = x; temp.y = y; clickCoordinates.push_back(temp); for (int i=0; i<clickCoordinates.size(); i++) cout<<clickCoordinates[i].x<<" "<<clickCoordinates[i].y<<endl; cout<<"\n"; } glutPostRedisplay(); } void init() { reshape(width,height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,width,0,height,-1,1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearColor(0, 0, 0, 0); //background color glPointSize(4.0); //point size = Pixel size } // inititalize OpenGL to standard values void initGL() { glClearColor (0, 0, 0, 0); // color, in which framebuffer is deleted glClearDepth (1.0f); // value to delete Z-Buffer glEnable (GL_DEPTH_TEST); // Z-Buffer test aktivated glDepthFunc (GL_LEQUAL); // Z-Buffer function (everything behind another poly is covered) glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //perspective computation of texturen } void render() { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // delete framebuffer & z-buffer glLoadIdentity(); //load origin coordinates glBindTexture(GL_TEXTURE_2D, OpenGLID); glEnable(GL_TEXTURE_2D); //render with texture glTranslatef(0,0,-3); //Seize of texture glBegin(GL_QUADS); glColor3f(1,1,1); glTexCoord2f(0,0); glVertex3f(-1,-1,1); glTexCoord2f(1,0); glVertex3f(1,-1,1); glTexCoord2f(1,1); glVertex3f(1,1,1); glTexCoord2f(0,1); glVertex3f(-1,1,1); glEnd(); } int main (int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(400, 400); glutCreateWindow("Admintool"); initGL(); // GL-default-values ilInit(); ILuint DevILID; // initialize DevIL ilGenImages(1,&DevILID); // generate IL ID for textures ilBindImage(DevILID); if (!ilLoadImage ("terra.jpg")) { ilDeleteImages(1,&DevILID); return false; } long h, v, bpp, f; unsigned char *texdata=0; h=ilGetInteger(IL_IMAGE_WIDTH); // width of image v=ilGetInteger(IL_IMAGE_HEIGHT); // heightof image bpp=ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL); // color-depthof image f=ilGetInteger(IL_IMAGE_FORMAT); // RGB RGBA BGR BGRA... texdata=ilGetData(); // pointer to imagedata glGenTextures(1,&OpenGLID); // same procedurre for OpenGL glBindTexture(GL_TEXTURE_2D, OpenGLID); // Images are loaded as mipmapp in OpenGL glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); gluBuild2DMipmaps(GL_TEXTURE_2D, bpp, h, v, f, GL_UNSIGNED_BYTE, texdata);/**/ render(); glutMouseFunc(mouse); glutDisplayFunc(display); init(); /* GLUI *glui = GLUI_Master.create_glui( "GLUI" ); glui->add_checkbox( "Wireframe", &wireframe ); GLUI_Spinner *segment_spinner = glui->add_spinner( "Segments:", GLUI_SPINNER_INT, &segments ); segment_spinner->set_int_limits( 3, 60 ); glui->set_main_gfx_window( main_window ); // We register the idle callback with GLUI, *not* with GLUT GLUI_Master.set_glutIdleFunc( myGlutIdle ); */ glutMainLoop(); return 0; }
-
also ohne codetags tu ich mir den code nicht an