?? rgbpixmap.h
字號(hào):
#ifndef _RGBPIXMAP
#define _RGBPIXMAP
#include <windows.h>
#include <assert.h>
#include <string>
#include <iostream>
#include <fstream>
#include <strstream>
using namespace std;
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
#include "common.h"
#include "shapes.h"
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned long ulong;
//$$$$$$$$$$$$$$$$$$$ class IntPoint $$$$$$$$$$$$$$
//$$$$$$$$$$$$$$$$$$ class mRGB $$$$$$$$$$$$$$$$$$
class mRGB{ // the name RGB is reserved in windows
public: uchar r,g,b;
mRGB(){r = g = b = 0;}
mRGB(mRGB& p){r = p.r; g = p.g; b = p.b;}
mRGB(uchar rr, uchar gg, uchar bb){r = rr; g = gg; b = bb;}
void set(uchar rr, uchar gg, uchar bb){r = rr; g = gg; b = bb;}
};
//$$$$$$$$$$$$$$$$$ RGBPixmap $$$$$$$$$$$$$$$
class RGBpixmap{
private:
mRGB* pixel; // array of pixels
GeomObj* obj;
public:
int nRows, nCols; // dimensions of the pixmap
int p;
RGBpixmap() {nRows = nCols = 0; pixel = 0;}
RGBpixmap(int rows, int cols) //constructor
{
nRows = rows;
nCols = cols;
pixel = new mRGB[rows*cols];
}
int readBMPFile(string fname); // read BMP file into this pixmap
int writeBMPFile(string fname); // write this pixmap to a BMP file
void setTexture(GLuint textureID);
void getObj(GeomObj* o){obj=o;};
void freeIt() // give back memory for this pixmap
{
delete []pixel;
nRows = nCols = 0;
}
//<<<<<<<<<<<<<<<<<< copy >>>>>>>>>>>>>>>>>>>
void copy(IntPoint from, IntPoint to, int x, int y, int width, int height)
{ // copy a region of the display back onto the display
if(nRows == 0 || nCols == 0) return;
glCopyPixels(x, y, width, height,GL_COLOR);
}
//<<<<<<<<<<<<<<<<<<< draw >>>>>>>>>>>>>>>>>
void draw()
{ // draw this pixmap at current raster position
if(nRows == 0 || nCols == 0) return;
//tell OpenGL NOT to try to align pixels to 4 byte boundaries in memory
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glDrawPixels(nCols, nRows,GL_RGB, GL_UNSIGNED_BYTE,pixel);
}
//<<<<<<<<<<<<<<<<< read >>>>>>>>>>>>>>>>
int read(int x, int y, int wid, int ht)
{ // read a rectangle of pixels into this pixmap
nRows = ht;
nCols = wid;
pixel = new mRGB[nRows *nCols]; if(!pixel) return -1;
//tell OpenGL NOT to try to align pixels to 4 byte boundaries in memory
glPixelStorei(GL_PACK_ALIGNMENT,1);
glReadPixels(x, y, nCols, nRows, GL_RGB,GL_UNSIGNED_BYTE,pixel);
return 0;
}
//<<<<<<<<<<<<<<<<< read from IntRect >>>>>>>>>>>>>>>>
int read(IntRect r)
{ // read a rectangle of pixels into this pixmap
nRows = r.t - r.b;
nCols = r.r - r.l;
pixel = new mRGB[nRows *nCols]; if(!pixel) return -1;
//tell OpenGL NOT to try to align pixels to 4 byte boundaries in memory
glPixelStorei(GL_PACK_ALIGNMENT,1);
glReadPixels(r.l,r.b, nCols, nRows, GL_RGB,GL_UNSIGNED_BYTE,pixel);
return 0;
}
//<<<<<<<<<<<<<< setPixel >>>>>>>>>>>>>
void setPixel(int x, int y, mRGB color)
{
if(x>=0 && x <nCols && y >=0 && y < nRows)
pixel[nCols * y + x] = color;
}
//<<<<<<<<<<<<<<<< getPixel >>>>>>>>>>>
mRGB getPixel(int x, int y)
{
mRGB bad(255,255,255);
if(x < 0 || x >= nCols || y < 0 || y >= nRows)
{
cout << "\nx,y = " << x << "," << y << " bad in getPixel()";
return bad;
}
return pixel[nCols * y + x];
}
}; //end of class RGBpixmap
#endif
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -