當我嘗試在OpenGL中用RGBA顏色繪製2D圓時,它用最接近的16色調色板繪製它。這是我使用的代碼。OpenGL在改變RGBA顏色後繪製了16種顏色
// Init canvas
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,Screen.Width(),Screen.Height(),0,0,1);
glMatrixMode(GL_MODELVIEW);
glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
// Background
glClearColor(0.0,0.0,0.0,1.0);
glShadeModel(GL_SMOOTH);
glClear(GL_COLOR_BUFFER_BIT);
[...]
glColor3f(Color.R,Color.G,Color.B);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(Pos.X - SX,Pos.Y - SY);
for (int angle=0; angle <= 360; angle+=1)
glVertex2f(Pos.X - SX + sin(angle*M_PI/180.0) * Size, Pos.Y - SY + cos(angle*M_PI/180.0) * Size);
glEnd();
[...]
// Render
glFlush();
glDisable(GL_COLOR_MATERIAL);
顏色爲Color
型的結構:
struct Color
{
float R;
float G;
float B;
float A;
void operator =(Color Clr);
bool operator ==(Color Clr);
};
下面的代碼用於設置發動機:
// Create context
GDC = GetDC(Handle);
// Create pixel format descriptor
PIXELFORMATDESCRIPTOR GPFD = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
24,
0,0,0,0,0,0,
0,0,
0,0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0
};
GPixelFormat = ChoosePixelFormat(GDC,&GPFD);
SetPixelFormat(GDC,GPixelFormat,&GPFD);
// Create resource
GRC = wglCreateContext(GDC);
wglMakeCurrent(GDC,GRC);
// Setup resource
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
我在做什麼錯?
UPDATE:
當我調試代碼,並與DescribePixelFormat()
讀取像素格式,調試器輸出以下:https://dl.dropboxusercontent.com/u/12669217/Debugger.jpg 此外,標誌PFD_GENERIC_FORMAT
和PFD_NEED_PALETTE
沒有設置。
這是所需的輸出(前我使用的OpenGL):https://dl.dropboxusercontent.com/u/12669217/CR_Desired.png
這是實際的輸出(文本和背景尚未實現):https://dl.dropboxusercontent.com/u/12669217/CR_Actual.png
任何改變,如果你設置爲'c [紅|綠|藍|阿爾法] [位|移]'爲零? – genpfault
如果使用'PFD_TYPE_RGBA',這個調色板的概念是沒有意義的。您需要使用「索引」顏色模式進行調色板渲染。 –
@genpfault不,依然如此。 – dengsn