When I try to draw a 2D circle in OpenGL with RGBA color, it draws it with the closest color of the 16-color palette. Here is the code I'm using.
// 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 is a structure of type Color :
struct Color { float R; float G; float B; float A; void operator =(Color Clr); bool operator ==(Color Clr); };
The following code is used to configure the engine:
// 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();
What am I doing wrong?
UPDATE:
When I debug this code and read the pixel format using DescribePixelFormat() , the debugger outputs the following: https://dl.dropboxusercontent.com/u/12669217/Debugger.jpg In addition, the PFD_GENERIC_FORMAT and PFD_NEED_PALETTE not set.
This is the desired result (before I used OpenGL): https://dl.dropboxusercontent.com/u/12669217/CR_Desired.png
This is the actual output (text and background not yet implemented): https://dl.dropboxusercontent.com/u/12669217/CR_Actual.png