예제 #1
0
파일: Texture.cpp 프로젝트: siquel/yam2d
void Texture::setTransparentColor(unsigned char r, unsigned char g, unsigned char b)
{
	assert( m_data != 0 );
	GLenum fmt;
	if( getBytesPerPixel() == 4 )
	{	
		fmt = GL_RGBA;
		for( int y=0; y<getHeight(); ++y )
		{
			for( int x=0; x<getWidth(); ++x )
			{
				unsigned char* data = getPixel(x,y);
				if( data[0] == r && data[1] == g && data[2] == b )
				{
					data[3] = 0;
				}
			}
		}
	}
	else if( getBytesPerPixel() == 3 )
	{		
		unsigned char* newData = new unsigned char[m_width*m_height*4];
		
		for( int y=0; y<getHeight(); ++y )
		{
			for( int x=0; x<getWidth(); ++x )
			{
				unsigned char* data = getPixel(x,y);
				unsigned char* d = &newData[(y*getWidth()+x)*4];
				d[0] = data[0];
				d[1] = data[1];
				d[2] = data[2];
				d[3] = 0xff;
				if( data[0] == r && data[1] == g && data[2] == b )
				{
					d[3] = 0x00;
				}
			}
		}

		m_bpp = 4;
		fmt = GL_RGBA;
		delete [] m_data;
		m_data = newData;
	}
	else
	{
		esLogEngineError("[%s] Unsupported bytes per pixel: %d", __FUNCTION__, m_bpp);
		return;
	}
	
	glBindTexture(GL_TEXTURE_2D, getNativeId());
	glTexImage2D(GL_TEXTURE_2D, 0, fmt, m_width, m_height, 0,  fmt, GL_UNSIGNED_BYTE, m_data );
	glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
예제 #2
0
파일: Texture.cpp 프로젝트: siquel/yam2d
int Texture::getNativeId() const
{
	return getNativeId(0);
}
예제 #3
0
파일: cursor.cpp 프로젝트: m64/PEG
	void Cursor::setNativeCursor(unsigned int cursor_id) {
#if defined( WIN32 ) || defined(__unix__)
		// Check if a value in NativeCursors is requested
		cursor_id = getNativeId(cursor_id);

		// Load cursor
#if defined( __unix__ )
		static Display* dsp = XOpenDisplay(NULL);
		XCursor xCursor = XcursorShapeLoadCursor(dsp, cursor_id);
		if (xCursor == 0) {
			if (m_native_cursor != NULL) {
				SDL_FreeCursor(m_native_cursor);
				m_native_cursor = NULL;
			}
			FL_WARN(_log, "Cursor: No cursor matching cursor_id was found.");
			return;
		}
#elif defined( WIN32 )
		// Load native cursor
		HCURSOR hIcon = LoadCursor(NULL, MAKEINTRESOURCE(cursor_id));
		if (hIcon == static_cast<HCURSOR>(0)) {
			if (m_native_cursor != NULL) {
				SDL_FreeCursor(m_native_cursor);
				m_native_cursor = NULL;
			}
			FL_WARN(_log, "Cursor: No cursor matching cursor_id was found.");
			return;
		}
#endif

		WMcursor *cursor;
		SDL_Cursor *curs2;

		// Allocate memory. Use SDL_FreeCursor to free cursor memory
		cursor = (WMcursor *)SDL_malloc(sizeof(*cursor));
		curs2 = (SDL_Cursor *)SDL_malloc(sizeof *curs2);

		//-- Set up some default values --
		curs2->wm_cursor = cursor;
		curs2->data = NULL;
		curs2->mask = NULL;
		curs2->save[0] = NULL;
		curs2->save[1] = NULL;
		curs2->area.x = 0;
		curs2->area.y = 0;
		curs2->area.w = 32;
		curs2->area.h = 32;
		curs2->hot_x = 0;
		curs2->hot_y = 0;

#if defined(WIN32)
		cursor->curs = hIcon;
#ifndef _WIN32_WCE
		cursor->ands = NULL;
		cursor->xors = NULL;
#endif

		// Get hot spot
		ICONINFO iconinfo;
		if (GetIconInfo(hIcon, &iconinfo)) {
			curs2->hot_x = static_cast<Sint16>(iconinfo.xHotspot);
			curs2->hot_y = static_cast<Sint16>(iconinfo.yHotspot);
		}

#elif defined(__unix__)
		cursor->x_cursor = xCursor;
		XSync(dsp, false);
#endif
		
		m_native_cursor = curs2;
		SDL_SetCursor(curs2);

#endif // WIN32 || __unix__
	}