Hello, i have some strange problem with destination alpha, to put it clear, i'll tell what i am doing: My init function looks like this:
glClearColor(0.7f, 0.7f, 0.9f, 0.1f);
glClearDepth(1.0f);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
As you see, i want to clear background with color (0.7,0.7,0.9,0.1) My drawing function looks like this
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,1,0,1,-1,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushAttrib(GL_ENABLE_BIT);
//Set Source Alpha to 1.0f
//But in this case it wont have any effect
glColor4f(1,1,0,1.0f);
glEnable(GL_BLEND);
//Use Dest Alpha for rendering with blend
glBlendFunc(GL_DST_ALPHA,GL_ZERO);
glBegin(GL_QUADS);
glVertex2f(0.0f,0.5f);
glVertex2f(0.0f,0.0f);
glVertex2f(0.5f,0.0f);
glVertex2f(0.5f,0.5f);
glEnd();
glColor4f(1,1,0,0.1f);
glBlendFunc(GL_SRC_ALPHA,GL_ZERO);
glBegin(GL_QUADS);
glVertex2f(0.5f,0.5f);
glVertex2f(0.5f,0.0f);
glVertex2f(1.0f,0.0f);
glVertex2f(1.0f,0.5f);
glEnd();
glPopAttrib();
glFlush();
As you can see i am drawing two quads, first one with destination alpha (0.1 - cause glClearColor(0.7f, 0.7f, 0.9f, 0.1f);), and second with source alpha (0.1 - cause glColor4f(1,1,0,0.1f);), two quads should look identical, but they don't, at least on my notebook (with Nvidia GeForce Go 7300) , i've tried to launch this app on Ati Radeon 9800 and works correctly, but i don't understand why it doesnt work on Nvidia, i have the latest drivers ... Please help if you have any ideas on this matter Here's the full code where opengl stuff of my main file
#include "GL_Includes.hpp"
#include "MainApp.h"
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glaux.lib")
void GL_Application::Create(const char * class_name)
{
CMainApp * example = new CMainApp(class_name);
app = reinterpret_cast<GL_Application *>(example);
}
// Class Constructor
CMainApp::CMainApp(const char * class_name) : GL_Application(class_name)
{
}
bool CMainApp::Initialize()
{
// Set Clear Color(0.7f, 0.7f, 0.9f, 0.0f)
// Not Alpha will be zero
glClearColor(0.7f, 0.7f, 0.9f, 0.1f);
glClearDepth(1.0f);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
return true;
}
void CMainApp::Deinitialize()
{
}
void CMainApp::Update(DWORD milliseconds)
{
float fDeltaTime = float(milliseconds)/1000.0f;
if (m_Keys.IsPressed(VK_ESCAPE) == true)
{
TerminateApplication();
}
}
void CMainApp::Draw()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,1,0,1,-1,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushAttrib(GL_ENABLE_BIT);
//Set Source Alpha to 0.0f
glColor4f(1,1,0,1.0f);
glEnable(GL_BLEND);
//Use Dest Alpha for rendering with blend
glBlendFunc(GL_DST_ALPHA,GL_ZERO);
glBegin(GL_QUADS);
glVertex2f(0.0f,0.5f);
glVertex2f(0.0f,0.0f);
glVertex2f(0.5f,0.0f);
glVertex2f(0.5f,0.5f);
glEnd();
glColor4f(1,1,0,0.1f);
glBlendFunc(GL_SRC_ALPHA,GL_ZERO);
glBegin(GL_QUADS);
glVertex2f(0.5f,0.5f);
glVertex2f(0.5f,0.0f);
glVertex2f(1.0f,0.0f);
glVertex2f(1.0f,0.5f);
glEnd();
glPopAttrib();
glFlush();
}
And just in case, where i'm creating opengl context, one
#include "GLWindow.h" // Header File For The GLWindow Basecode
#include <gl/gl.h> // Header File For The OpenGL32 Library
#include <gl/glu.h> // Header File For The GLu32 Library
// Initialize Class Default Values
GL_Window::GL_Window() // Class Constructor
{
m_WindowPosX = 0; // Window X Position
m_WindowPosY = 0; // Window Y Position
m_WindowWidth = 800; // Window Width
m_WindowHeight = 600; // Window Height
m_ScreenWidth = 800; // Screen Width
m_ScreenHeight = 600; // Screen Height
m_BitsPerPixel = 16; // Bits Per Pixel
m_IsFullScreen = false; // Fullscreen
m_hWnd = 0;
m_hDC = 0;
m_hRC = 0;
}
// Get Window Dimensions Depending On Screen Mode (FullScreen / Windowed)
int GL_Window::GetWidth()
{
if (m_IsFullScreen == true)
{
return m_ScreenWidth;
}
else
{
return m_WindowWidth;
}
}
int GL_Window::GetHeight()
{
if (m_IsFullScreen == true)
{
return m_ScreenHeight;
}
else
{
return m_WindowHeight;
}
}
// Set Window Dimensions Depending On Screen Mode (FullScreen / Windowed)
void GL_Window::SetWidth(int width)
{
if (m_IsFullScreen == true)
{
m_ScreenWidth = width;
}
else
{
m_WindowWidth = width;
}
}
void GL_Window::SetHeight(int height)
{
if (m_IsFullScreen == true)
{
m_ScreenHeight = height;
}
else
{
m_WindowHeight = height;
}
}
// Get Window Position Depending On Screen Mode (FullScreen / Windowed)
int GL_Window::GetPosX()
{
if (m_IsFullScreen == false)
{
return m_WindowPosX;
}
return 0;
}
int GL_Window::GetPosY()
{
if (m_IsFullScreen == false)
{
return m_WindowPosY;
}
return 0;
}
// Set Window Position Depending On Screen Mode (FullScreen / Windowed)
void GL_Window::SetPosX(int x)
{
if (m_IsFullScreen == false)
{
m_WindowPosX = x;
}
}
void GL_Window::SetPosY(int y)
{
if (m_IsFullScreen == false)
{
m_WindowPosY = y;
}
}
// Reshape The Window When It's Resized
void GL_Window::ReshapeGL()
{
GLsizei width = GetWidth();
GLsizei height = GetHeight();
glViewport(0, 0, width, height); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
gluPerspective(45.0f, (GLfloat)width / (GLfloat)height, 1.0f, 1000.0f); // Calculate The Aspect Ratio Of The Window
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
}
// Change The Screen Resolution
bool GL_Window::ChangeScreenResolution()
{
DEVMODE dmScreenSettings; // Device Mode
ZeroMemory(&dmScreenSettings, sizeof(DEVMODE)); // Make Sure Memory Is Cleared
dmScreenSettings.dmSize = sizeof(DEVMODE); // Size Of The Devmode Structure
dmScreenSettings.dmPelsWidth = GetWidth(); // Select Window Width
dmScreenSettings.dmPelsHeight = GetHeight(); // Select Window Height
dmScreenSettings.dmBitsPerPel = m_BitsPerPixel; // Select Bits Per Pixel
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
{
return false; // Display Change Failed, Return false
}
return true; // Display Change Was Successful, Return true
}
// Create OpenGL Window
bool GL_Window::Create(const char * window_title, bool full_screen, const char * class_name, HINSTANCE h_instance, LPVOID lpParam)
{
m_IsFullScreen = full_screen;
PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_STEREO | // Only supported by few Cards (such as ASUS and ELSA GeForce series, and GF Quadro series) with Stereo-glasses
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
m_BitsPerPixel, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // No Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
16, // 16Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};
DWORD windowstyle = WS_OVERLAPPEDWINDOW; // Define Our Window style
DWORD windowExtendedstyle = WS_EX_APPWINDOW; // Define The Window's Extended style
if (m_IsFullScreen == true) // Fullscreen Requested, Try Changing Video Modes
{
if (ChangeScreenResolution() == false)
{ // Fullscreen Mode Failed. Run In Windowed Mode Instead
MessageBox(HWND_DESKTOP, "Mode Switch Failed.\nRunning In Windowed Mode.", "Error", MB_OK | MB_ICONEXCLAMATION);
m_IsFullScreen = false; // Set isFullscreen To false (Windowed Mode)
}
else // Otherwise (If Fullscreen Mode Was Successful)
{
ShowCursor(false); // Turn Off The Cursor
windowstyle = WS_POPUP; // Set The Windowstyle To WS_POPUP (Popup Window)
windowExtendedstyle |= WS_EX_TOPMOST; // Set The Extended Window style To WS_EX_TOPMOST
} // (Top Window Covering Everything Else)
}
// Define Our Window Coordinates
RECT windowRect = {GetPosX(), GetPosY(), GetPosX() + GetWidth(), GetPosY() + GetHeight()};
if (m_IsFullScreen == false) // If Fullscreen Was Not Selected
{ // Adjust Window, Account For Window Borders
AdjustWindowRectEx(&windowRect, windowstyle, 0, windowExtendedstyle);
// Check If Window's Left-Top Corner Is Inside The DeskTop
if (windowRect.left < 0) // If Window X Position Negative
{
windowRect.right -= windowRect.left; // Correct Right Position
windowRect.left = 0; // Move Window To X Position 0
}
if (windowRect.top < 0) // If Window Y Position Negative
{
windowRect.bottom -= windowRect.top; // Correct Bottom Position
windowRect.top = 0; // Move Window To Y Position 0
}
}
// Create The OpenGL Window
m_hWnd = CreateWindowEx(windowExtendedstyle, // Extended style
class_name, // Class Name
window_title, // Window Title
windowstyle, // Window style
windowRect.left, windowRect.top, // Window X,Y Position
windowRect.right - windowRect.left, // Window Width
windowRect.bottom - windowRect.top, // Window Height
HWND_DESKTOP, // Desktop Is Window's Parent
0, // No Menu
h_instance, // Pass The Window Instance
lpParam); // Pass The Application Class Context
while (m_hWnd != 0) // Was Window Creation A Success?
{
m_hDC = GetDC(m_hWnd); // Grab A Device Context For This Window
if (m_hDC == 0) // Did We Get A Device Context?
{ // Failed
break; // GoTo End Of while (m_hWnd != 0) Block
}
GLuint PixelFormat = ChoosePixelFormat(m_hDC, &pfd); // Find A Compatible Pixel Format
if (PixelFormat == 0) // Did We Find A Compatible Format?
{ // Failed
break; // GoTo End Of while (m_hWnd != 0) Block
}
if (SetPixelFormat(m_hDC, PixelFormat, &pfd) == false) // Try To Set The Pixel Format
{ // Failed
break; // GoTo End Of while (m_hWnd != 0) Block
}
m_hRC = wglCreateContext(m_hDC); // Try To Get A Rendering Context
if (m_hRC == 0) // Did We Get A Rendering Context?
{ // Failed
break; // GoTo End Of while (m_hWnd != 0) Block
}
if (wglMakeCurrent(m_hDC, m_hRC) == false) // Make The Rendering Context Our Current Rendering Context
{ // Failed
break; // GoTo End Of while (m_hWnd != 0) Block
}
ShowWindow(m_hWnd, SW_NORMAL); // Make The Window Visible
ReshapeGL(); // Reshape Our GL Window
return true; // Window Creating Was A Success
} // Initialization Will Be Done In WM_CREATE
Destroy(); // Free Resources
return false; // If Any Error Return false
}
// Destroy OpenGL Window
void GL_Window::Destroy() // Destroy The OpenGL Window & Release Resources
{
if (m_hWnd != 0) // Does The Window Have A Handle?
{
if (m_hDC != 0) // Does The Window Have A Device Context?
{
wglMakeCurrent(m_hDC, 0); // Set The Current Active Rendering Context To Zero
if (m_hRC != 0) // Does The Window Have A Rendering Context?
{
wglDeleteContext(m_hRC); // Release The Rendering Context
m_hRC = 0; // Zero The Rendering Context
}
ReleaseDC(m_hWnd, m_hDC); // Release The Device Context
m_hDC = 0; // Zero The Device Context
}
DestroyWindow(m_hWnd); // Destroy The Window
m_hWnd = 0; // Zero The Window Handle
}
if (m_IsFullScreen) // Is Window In Fullscreen Mode
{
ChangeDisplaySettings(NULL, 0); // Switch Back To Desktop Resolution
ShowCursor(true); // Show The Cursor
}
}
There's a possibility that pixel format is incorrect... Link to full code http://www.megaupload.com/?d=3WFM7RFO Correct pic

Incorrect pic