Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //The issue is that the draw function is drawing only a black rectangle
- //to the window I generate.
- //I have verified that the array of Pixel objects has been filled
- //correctly, and remains filled correctly even after the program
- //advances past the texture creation.
- class Pixel
- {
- private:
- unsigned char r; //The Red value
- unsigned char g; //The Green value
- unsigned char b; //The Blue value
- public:
- Pixel(): r(0), g(0), b(0) {}
- Pixel(char R, char G, char B): r(R), g(G), b(B) {}
- ~Pixel(){}
- void setR(unsigned char R) {r = R;}
- void setG(unsigned char G) {g = G;}
- void setB(unsigned char B) {b = B;}
- const unsigned char R() {return r;}
- const unsigned char G() {return g;}
- const unsigned char B() {return b;}
- };
- class Image
- {
- private:
- int width; //The width of the image
- int height; //The height of the image
- Pixel * pix; //List of the image pixels
- public:
- Image();
- Image(std::string);
- ~Image()
- {
- delete pix;
- }
- Image(const Image&);
- Image& operator=(const Image&);
- void readFile(std::ifstream&); //Read the image into the pixels
- int getHeight() {return height;}
- int getWidth() {return width;}
- const void draw(); //Draw the image to the screen
- };
- const void Image::draw()
- {
- GLuint tex = 0;
- GLuint verts[][5] = {{0,0,0,0,0}, {width,0,0,1,0}, {0,height,0,0,1}, {width,height,0,1,1}};
- glGenTextures(1, &tex);
- glBindTexture(GL_TEXTURE_2D, tex);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- // upload texture data
- glTexImage2D(GL_TEXTURE_2D, 0, 3, /*GL_RGB,*/ width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, pix);
- /*
- * You only have to enable/disable when you are going to be drawing in a
- * different mode on subsequent calls. Leaving in for good measure.
- */
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- // Point to vertex data and draw the strip.
- glVertexPointer(3, GL_FLOAT, sizeof(float)*5, verts);
- glTexCoordPointer(2, GL_FLOAT, sizeof(float)*5, verts+3);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glDisableClientState(GL_VERTEX_ARRAY);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement