void GVOGameProcess::grabImage( HDC hdc, const POINT& offset, const SIZE& size )
{
if ( !m_surveyCoordImage.bitmapHandle() ) {
- m_surveyCoordImage.createDIBImage( k_surveyCoordSize );
+ m_surveyCoordImage.createImage( k_surveyCoordSize );
}
HDC hdcMem = ::CreateCompatibleDC( hdc );
const int height = bmp.bmHeight;
::EnterCriticalSection( &m_lock );
- m_shipIconImage.createRGBAImage( width, height );
+ m_shipIconImage.createImage( width, height, k_GVOPixelFormat_RGBA );
uint32_t * d = reinterpret_cast<uint32_t*>(m_shipIconImage.mutableImageBits());
for ( int y = 0; y < height; ++y ) {
bool GVOImage::stretchCopy( const GVOImage& src, uint32_t width, uint32_t height )
{
- if ( !createDIBImage( width, height ) ) {
+ if ( !createImage( width, height ) ) {
return false;
}
::BitBlt( hdcDst, 0, 0, m_size.cx, m_size.cy,
hdcSrc, 0, 0, SRCCOPY );
}
+ m_pixelFormat = src.m_pixelFormat;
+
::RestoreDC( hdcSrc, -1 );
::DeleteDC( hdcSrc );
::RestoreDC( hdcDst, -1 );
::DeleteDC( hdcDst );
::ReleaseDC( NULL, hdc );
- m_fileName = L"";
return true;
}
-bool GVOImage::createRGBAImage( int width, int height )
+bool GVOImage::createImage( int width, int height, GVOPixelFormat pixelFormat )
{
reset();
- BITMAPV5HEADER bmih = { sizeof(bmih) };
- bmih.bV5Compression = BI_BITFIELDS;
- bmih.bV5BlueMask = 0xFF;
- bmih.bV5GreenMask = 0xFF << 8;
- bmih.bV5RedMask = 0xFF << 16;
- bmih.bV5AlphaMask = 0xFF << 24;
- bmih.bV5Width = width;
- bmih.bV5Height = -height;
- bmih.bV5Planes = 1;
- bmih.bV5BitCount = 32;
- bmih.bV5SizeImage = width * height * 4;
- m_hbmp = ::CreateDIBSection( NULL, (LPBITMAPINFO)&bmih, DIB_RGB_COLORS, (void **)&m_bits, NULL, 0 );
- if ( !m_hbmp ) {
+ uint32_t bitCount = 0;
+
+ if ( pixelFormat == k_GVOPixelFormat_RGB ) {
+ BITMAPINFOHEADER bmih = { sizeof(bmih) };
+ bmih.biWidth = width;
+ bmih.biHeight = -height;
+ bmih.biPlanes = 1;
+ bmih.biBitCount = 24;
+ bmih.biSizeImage = width * height * 3;
+ m_hbmp = ::CreateDIBSection( NULL, (LPBITMAPINFO)&bmih, DIB_RGB_COLORS, (void **)&m_bits, NULL, 0 );
+ bitCount = bmih.biBitCount;
+ }
+ else if ( pixelFormat == k_GVOPixelFormat_RGBA ) {
+ BITMAPV5HEADER bmih = { sizeof(bmih) };
+ bmih.bV5Compression = BI_BITFIELDS;
+ bmih.bV5BlueMask = 0xFF;
+ bmih.bV5GreenMask = 0xFF << 8;
+ bmih.bV5RedMask = 0xFF << 16;
+ bmih.bV5AlphaMask = 0xFF << 24;
+ bmih.bV5Width = width;
+ bmih.bV5Height = -height;
+ bmih.bV5Planes = 1;
+ bmih.bV5BitCount = 32;
+ bmih.bV5SizeImage = width * height * 4;
+ m_hbmp = ::CreateDIBSection( NULL, (LPBITMAPINFO)&bmih, DIB_RGB_COLORS, (void **)&m_bits, NULL, 0 );
+ bitCount = bmih.bV5BitCount;
+ }
+ else {
+ abort();
return false;
}
- m_size.cx = width;
- m_size.cy = height;
- m_stride = width;
- m_fileName = L"";
- return true;
-}
-
-
-bool GVOImage::createDIBImage( int width, int height )
-{
- reset();
-
- BITMAPINFOHEADER bmih = { sizeof(bmih) };
- bmih.biWidth = width;
- bmih.biHeight = -height;
- bmih.biPlanes = 1;
- bmih.biBitCount = 24;
- bmih.biSizeImage = width * height * 3;
- m_hbmp = ::CreateDIBSection( NULL, (LPBITMAPINFO)&bmih, DIB_RGB_COLORS, (void **)&m_bits, NULL, 0 );
if ( !m_hbmp ) {
return false;
}
m_size.cx = width;
m_size.cy = height;
- m_stride = s_strideFromWidthAndBitsPerPixel( width, bmih.biBitCount );
- m_fileName = L"";
+ m_pixelFormat = pixelFormat;
+ m_stride = s_strideFromWidthAndBitsPerPixel( width, bitCount );
return true;
}
HBITMAP hbmp = NULL;
image.reset( Gdiplus::Bitmap::FromFile( fileName.c_str() ) );
image->GetHBITMAP( Gdiplus::Color( 0, 0, 0 ), &hbmp );
+ Gdiplus::PixelFormat srcPixelFormat = image->GetPixelFormat();
image.reset();
if ( !hbmp ) {
return false;
}
+
+ GVOPixelFormat pixelFormat;
+
+ if ( srcPixelFormat & PixelFormatGDI ){
+ pixelFormat = k_GVOPixelFormat_RGB;
+ }
+ else if ( srcPixelFormat & (PixelFormatGDI | PixelFormatAlpha) ) {
+ pixelFormat = k_GVOPixelFormat_RGBA;
+ }
+ else {
+ abort();
+ return false;
+ }
+
BITMAP bmp = { 0 };
::GetObject( hbmp, sizeof(bmp), &bmp );
- if ( !createDIBImage( bmp.bmWidth, bmp.bmHeight ) ) {
+ if ( !createImage( bmp.bmWidth, bmp.bmHeight, pixelFormat ) ) {
::DeleteObject( hbmp );
return false;
}
::GetBitmapBits( hbmp, buffer.size(), &buffer[0] );
::DeleteObject( hbmp );
- switch ( bmp.bmBitsPixel ) {
- case 24:
+ if ( pixelFormat == k_GVOPixelFormat_RGB ) {
+ switch ( bmp.bmBitsPixel ) {
+ case 24:
+ ::memcpy( m_bits, &buffer[0], m_stride );
+ break;
+ case 32:
+ ::s_copyImage24From32( m_bits, &buffer[0], m_size.cx, m_size.cy );
+ break;
+ default:
+ return false;
+ }
+ }
+ else if ( pixelFormat == k_GVOPixelFormat_RGBA ) {
::memcpy( m_bits, &buffer[0], m_stride );
- break;
- case 32:
- ::s_copyImage24From32( m_bits, &buffer[0], m_size.cx, m_size.cy );
- break;
- default:
+ }
+ else {
+ abort();
return false;
}
-
- m_fileName = fileName;
-
return true;
}
#include "GVONoncopyable.h"
+//!@brief \89æ\91\9c\82Ì\83s\83N\83Z\83\8b\83t\83H\81[\83}\83b\83g
+enum GVOPixelFormat {
+ k_GVOPixelFormat_Unknown, //!<@brief \96¢\92è\8b`\92l
+ k_GVOPixelFormat_RGB, //!<@brief R8G8B8
+ k_GVOPixelFormat_RGBA, //!<@brief R8G8B8A8
+};
+
class GVOImage :private GVONoncopyable {
private:
- std::wstring m_fileName;
HBITMAP m_hbmp;
SIZE m_size;
+ GVOPixelFormat m_pixelFormat;
uint8_t * m_bits;
uint32_t m_stride;
::DeleteObject( m_hbmp );
m_hbmp = NULL;
}
- m_fileName = L"";
m_size = SIZE();
m_stride = 0;
+ m_pixelFormat = k_GVOPixelFormat_Unknown;
}
void copy( const GVOImage & src )
{
- createDIBImage( src.m_size );
+ createImage( src.m_size, src.m_pixelFormat );
::memcpy( m_bits, src.m_bits, src.m_size.cy * src.m_stride );
}
bool stretchCopy( const GVOImage& src, const SIZE& size )
{
return m_size.cy;
}
+ GVOPixelFormat pixelFormat() const
+ {
+ return m_pixelFormat;
+ }
uint32_t stride() const
{
return m_stride;
{
return m_bits;
}
- const std::wstring& fileName() const
- {
- return m_fileName;
- }
- bool createRGBAImage( int width, int height );
- bool createDIBImage( int width, int height );
- bool createDIBImage( const SIZE& size )
+ bool createImage( int width, int height, GVOPixelFormat pixelFormat = k_GVOPixelFormat_RGB );
+ bool createImage( const SIZE& size, GVOPixelFormat pixelFormat = k_GVOPixelFormat_RGB )
{
- return createDIBImage( size.cx, size.cy );
+ return createImage( size.cx, size.cy, pixelFormat );
}
bool loadFromFile( const std::wstring& fileName );
};
static const double k_knotFactor = (2 * M_PI * 6378.137) / 16384.0 / 0.4 / 1.852;
return velocity * k_knotFactor;
}
-
- //GVOImage m_shipImage;
- //GVOTexture m_shipImageTexture;
}
setConfig( config );
setupGL();
setWorldMap( worldMap );
-
- //m_shipImage.createRGBAImage( 16, 16 );
- //uint32_t * dst = reinterpret_cast<uint32_t *>(m_shipImage.mutableImageBits());
- //for ( int y = 0; y < m_shipImage.height(); ++y ) {
- // for ( int x = 0; x < m_shipImage.width(); ++x ) {
- // *dst++ = RGB(255,0,0) | (y*15) << 24;
- // }
- //}
- //m_shipImageTexture.setImageWithAlpha( &m_shipImage );
}
{
m_worldMap = worldMap;
m_worldMapTexture = new GVOTexture();
- m_worldMapTexture->setImage( &worldMap->image() );
+ m_worldMapTexture->setImage( worldMap->image() );
}
::glTranslatef( (float)xDrawOrigin, (float)yDrawOrigin, 0 );
while ( drawn < m_viewSize.cx ) {
// \92n\90}\82ð1\96\87\95`\89æ
- m_worldMapTexture->bind();
- renderTexture( (float)mapSize.cx, (float)mapSize.cy );
- m_worldMapTexture->unbind();
+ renderTexture( *m_worldMapTexture, (float)mapSize.cx, (float)mapSize.cy );
// \8fI\92\85\82µ\82Ä\82¢\82È\82¢\8dq\98H\82ð1\96\87\95ª\95`\89æ
renderShipRouteList( mapSize.cx, mapSize.cy, shipRouteList );
::glEnable( GL_BLEND );
::glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
::glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
- shipTexture->bind();
- renderTexture( x, y, shipMarkSize, shipMarkSize );
- shipTexture->unbind();
+ renderTexture( *shipTexture, x, y, shipMarkSize, shipMarkSize );
::glDisable( GL_BLEND );
xDrawOrigin += mapSize.cx;
void GVORenderer::renderSpeedMeter( double shipVelocity )
{
- // THE\8eè\94²\82«\95¶\8e\9a\83|\83\8a\83S\83\93\8dì\90¬
+ // THE\8eè\94²\82«\95¶\8e\9a\83e\83N\83X\83`\83\83\81[\8dì\90¬
HDC hdcMem = ::CreateCompatibleDC( m_hdcPrimary );
::SaveDC( hdcMem );
const int stride = width + (4 - width % 4) % 4;
const int height = rc.bottom - rc.top;
GVOImage workImage;
- workImage.createDIBImage( stride, height );
+ workImage.createImage( stride, height );
::SelectObject( hdcMem, workImage.bitmapHandle() );
::DrawText( hdcMem, buf, -1, &rc, DT_SINGLELINE | DT_RIGHT | DT_TOP );
::RestoreDC( hdcMem, -1 );
::DeleteDC( hdcMem );
GVOTexture workTexture;
- workTexture.setImage( &workImage );
+ workTexture.setImage( workImage );
::glMatrixMode( GL_MODELVIEW );
::glLoadIdentity();
- workTexture.bind();
- renderTexture( float( m_viewSize.cx - stride ), 0.0f, (float)stride, (float)height );
- workTexture.unbind();
+ renderTexture( workTexture, float( m_viewSize.cx - stride ), 0.0f, (float)stride, (float)height );
}
-void GVORenderer::renderTexture( float w, float h )
+void GVORenderer::renderTexture( GVOTexture & texture, float w, float h )
{
- renderTexture( 0, 0, w, h );
+ renderTexture( texture, 0, 0, w, h );
}
-void GVORenderer::renderTexture( float x, float y, float w, float h )
+void GVORenderer::renderTexture( GVOTexture & texture, float x, float y, float w, float h )
{
+ texture.bind();
+
::glBegin( GL_QUADS );
::glTexCoord2d( 0, 0 );
::glVertex2d( x + w, y );
::glEnd();
+
+ texture.unbind();
}
{
::wglMakeCurrent( m_hdcPrimary, m_hglrc );
std::auto_ptr<GVOTexture> texture( new GVOTexture() );
- texture->setImageWithAlpha( &image );
+ texture->setImage( image );
::wglMakeCurrent( NULL, NULL );
return texture.release();
HDC m_hdcPrimary;
HGLRC m_hglrc;
- GVOImage m_backBuffer;
SIZE m_viewSize;
double m_viewScale;
void renderMap( const GVOVector& shipVector, GVOTexture * shipTexture, const GVOShipRouteList * shipRouteList );
void renderShipRouteList(int width, int height, const GVOShipRouteList * shipRouteList );
void renderSpeedMeter( double shipVelocity );
- void renderTexture( float w, float h );
- void renderTexture( float x, float y, float w, float h );
+ void renderTexture( GVOTexture & texture, float w, float h );
+ void renderTexture( GVOTexture & texture, float x, float y, float w, float h );
inline POINT viewCenterPoint() const
{
POINT p = {
}
-void GVOTexture::setImage( const GVOImage * image )
+void GVOTexture::setImage( const GVOImage & image )
{
- if ( image ) {
- bind();
+ bind();
+ if ( image.pixelFormat() == k_GVOPixelFormat_RGB ) {
::glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
::glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB,
- image->width(), image->height(),
+ image.width(), image.height(),
0, GL_BGR_EXT,
- GL_UNSIGNED_BYTE, image->imageBits() );
- m_width = image->width();
- m_height = image->height();
-
- unbind();
+ GL_UNSIGNED_BYTE, image.imageBits() );
}
-}
-
-
-void GVOTexture::setImageWithAlpha( const GVOImage * image )
-{
- if ( image ) {
- bind();
-
+ else if ( image.pixelFormat() == k_GVOPixelFormat_RGBA ) {
::glPixelStorei( GL_UNPACK_ALIGNMENT, 4 );
::glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
- image->width(), image->height(),
+ image.width(), image.height(),
0, GL_BGRA_EXT,
- GL_UNSIGNED_BYTE, image->imageBits() );
- m_width = image->width();
- m_height = image->height();
-
- unbind();
+ GL_UNSIGNED_BYTE, image.imageBits() );
}
+ else {
+ abort();
+ }
+ m_width = image.width();
+ m_height = image.height();
+
+ unbind();
}
#pragma once
#include "GVONoncopyable.h"
+#include "GVOImage.h"
+
-class GVOImage;
//!@brief OpenGL\83e\83N\83X\83`\83\83\83N\83\89\83X
class GVOTexture : private GVONoncopyable {
return m_height;
}
- void setImage( const GVOImage * image );
- void setImageWithAlpha( const GVOImage * image );
+ void setImage( const GVOImage & image );
+
void bind();
+
void unbind();
};