Greetings.
Please help…
I try to port some games from HGE engine to own, based on SDL/OpenGL.
Almost everything works fine
But I discovered small difference in render results between rendering
through SDL/OpenGL on Windows and Mac OS X.
There are two screenshots:
Windows
http://motosvit.com/Anand/mac/Windows_screenshot.png
Mac OS X
http://motosvit.com/Anand/mac/MacOSX_screenshot.png
Corresponding .png files are here:
http://motosvit.com/Anand/mac/bg2.png
http://motosvit.com/Anand/mac/logo.png
Difference is around the logo - Mac OS X render it with dark border.
I tested on the same computer where both Mac OS X 10.5 and Vista are
installed - so video card was the same.
I got the same result on 10.4 (old PowerBook with PowerPC).
The question - what is the cause of this difference?
The test application is very simple. I pasted here OSX version. Windows
version differs only in path to image files. Renderers are OpenGL for
both cases.
I used latest SDL 1.3 and SDL_image from SVN to reproduce this behavior.
Thank you
//
// main.m
// SDL_test
//
// Created by user on 3/18/09.
// Copyright MyCompanyName 2009. All rights reserved.
//
#include “SDL.h”
#include “SDL_image.h”
#include “BfxWorkingDirectory.h”
#include
#include <OpenGL/OpenGL.h>
int main(int argc, char** argv)
{
try
{
//Init SDL here - it will initialize SDL timer in right time
SDL_Init(SDL_INIT_EVERYTHING);
if (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1))
return 1;
if (SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0))
return 2;
if (SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8))
return 3;
if (SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8))
return 4;
if (SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8))
return 5;
if (SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8))
return 6;
SDL_EnableUNICODE(1);
bool fullscreen = false;//true;
SDL_WindowID windowid = 0;
unsigned int flags = (fullscreen ? SDL_WINDOW_FULLSCREEN : 0) |
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
int windowwidth = 800;
int windowheight = 600;
if (!fullscreen)
windowid = SDL_CreateWindow("Test application" ,
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowwidth, windowheight,
flags);
else
{
}
if (!windowid)
return 3;
//select renderer
int driver_count = SDL_GetNumRenderDrivers();
int opengl_index = -1;
for (int i=0; i<driver_count && opengl_index == -1; ++i)
{
SDL_RendererInfo info;
SDL_GetRenderDriverInfo(i, &info);
if (strcmp(info.name, "opengl") == 0)
opengl_index = i;
}
if (opengl_index == -1)
return 4;
if (SDL_CreateRenderer(windowid, opengl_index, 0))
return 5;
//load the test image
SetWorkingDirectoryToResources();
SDL_Surface* background = IMG_Load("bg2.png");
if (!background)
{
printf("Cant load image.\n");
SDL_Quit();
return 1;
}
SDL_TextureID backgroundTexture = SDL_CreateTextureFromSurface(0,
background);
if (!backgroundTexture)
{
printf(“Cant create OpenGL texture from surface.\n”);
SDL_FreeSurface(background);
SDL_Quit();
return 1;
}
SDL_FreeSurface(background);
SDL_Surface* logo = IMG_Load("logo.png");
if (!logo)
{
printf("Cant load image.\n");
SDL_Quit();
return 1;
}
SDL_TextureID logoTexture = SDL_CreateTextureFromSurface(0, logo);
if (!logoTexture)
{
printf("Cant create OpenGL texture from surface. \n");
SDL_FreeSurface(logo);
SDL_Quit();
return 1;
}
bool mousepressed = false;
//run the event loop
while (true)
{
SDL_Event _event;
while(SDL_PollEvent(&_event)) {
switch (_event.type)
{
case SDL_QUIT:
return 0;
case SDL_WINDOWEVENT:
case SDL_SYSWMEVENT:
case SDL_WINDOWEVENT_CLOSE:
break;
case SDL_MOUSEMOTION:
break;
case SDL_MOUSEBUTTONDOWN:
mousepressed = true;
break;
case SDL_MOUSEBUTTONUP:
mousepressed = false;
break;
case SDL_MOUSEWHEEL:
break;
case SDL_KEYDOWN:
if (_event.key.keysym.scancode == SDL_SCANCODE_ESCAPE)
return 0;
break;
}
}
// Process keys
SDL_Rect dest;
dest.x = 0; dest.y = 0; dest.w = 800; dest.h = 600;
SDL_RenderCopy(backgroundTexture, NULL, &dest);
// SDL_BLENDMODE_NONE = 0x00000000, /**< No blending */
// SDL_BLENDMODE_MASK = 0x00000001, /**< dst = A ? src : dst
(alpha is mask) */
// SDL_BLENDMODE_BLEND = 0x00000002, /< dst = (src * A) +
(dst * (1-A)) */
// SDL_BLENDMODE_ADD = 0x00000004, /< dst = (src * A) + dst */
// SDL_BLENDMODE_MOD = 0x00000008 /**< dst = src * dst */
dest.x = 400 - 128;
dest.y = 0;
dest.w = 256;
dest.h = 256;
SDL_SetTextureBlendMode(logoTexture, 2);
SDL_RenderCopy(logoTexture, NULL, &dest);
SDL_RenderPresent();
//do not waste 100% CPU
SDL_Delay(1);
}
SDL_DestroyTexture(backgroundTexture);
SDL_DestroyTexture(logoTexture);
//quit
SDL_DestroyRenderer(windowid);
SDL_DestroyWindow(windowid);
SDL_Quit();
}
catch(std::exception& e)
{
//std::cerr << "Exception occured: " << e.what() << endl;
}
return 0;
}