Browse Source

- opengl work on Linux systems
- compile fixes for gcc

Ivan Savenko 12 years ago
parent
commit
54506e7c29

+ 1 - 0
CMakeLists.txt

@@ -50,6 +50,7 @@ find_package(SDL_image REQUIRED)
 find_package(SDL_mixer REQUIRED)
 find_package(SDL_ttf REQUIRED)
 find_package(ZLIB REQUIRED)
+find_package(OpenGL REQUIRED)
 
 if (ENABLE_EDITOR)
 	# Widgets finds its own dependencies (QtGui and QtCore).

+ 3 - 3
client/AdventureMapClasses.cpp

@@ -580,14 +580,14 @@ void CMinimap::showAll()
 		int3 mapSizes = LOCPLINT->cb->getMapSize();
 
 		//draw radar
-		SDL_Rect oldClip;
-		SDL_Rect radar =
+		// SDL_Rect oldClip;
+		/*SDL_Rect radar =
 		{
 			si16(adventureInt->position.x * pos.w / mapSizes.x + pos.x),
 			si16(adventureInt->position.y * pos.h / mapSizes.y + pos.y),
 			ui16(adventureInt->terrain.tilesw * pos.w / mapSizes.x),
 			ui16(adventureInt->terrain.tilesh * pos.h / mapSizes.y)
-		};
+		};*/
 
 		//* SDL_GetClipRect(to, &oldClip);
 		//* SDL_SetClipRect(to, &pos);

+ 6 - 6
client/BattleInterface/CCreatureAnimation.cpp

@@ -228,7 +228,7 @@ int CCreatureAnimation::nextFrameT(SDL_Surface * dest, int x, int y, bool attack
 				const int remainder = ftcp % FullWidth;
 				int xB = (attacker ? remainder : FullWidth - remainder - 1) + x;
 
-				const ui8 aCountMod = (animCount & 0x20) ? ((animCount & 0x1e) >> 1) << 4 : (0x0f - ((animCount & 0x1e) >> 1)) << 4;
+				//const ui8 aCountMod = (animCount & 0x20) ? ((animCount & 0x1e) >> 1) << 4 : (0x0f - ((animCount & 0x1e) >> 1)) << 4;
 
 				for (int k = 0; k <= SegmentLength; k++)
 				{
@@ -236,7 +236,7 @@ int CCreatureAnimation::nextFrameT(SDL_Surface * dest, int x, int y, bool attack
 					{
 						if(!destRect || (destRect->x <= xB && destRect->x + destRect->w > xB && destRect->y <= yB && destRect->y + destRect->h > yB))
 						{
-							const ui8 colorNr = SegmentType == 0xff ? FDef[BaseOffset+k] : SegmentType;
+							//const ui8 colorNr = SegmentType == 0xff ? FDef[BaseOffset+k] : SegmentType;
 							//putPixel<bpp>(dest, xB, yB, palette[colorNr], colorNr, yellowBorder, blueBorder, aCountMod);
 						}
 					}
@@ -299,7 +299,7 @@ inline void CCreatureAnimation::putPixel(
 	SDL_Surface * dest,
 	const int & ftcpX,
 	const int & ftcpY,
-	const BMPPalette & color,
+	const SDL_Color & color,
 	const ui8 & palc,
 	const bool & yellowBorder,
 	const bool & blueBorder,
@@ -311,7 +311,7 @@ inline void CCreatureAnimation::putPixel(
 		Uint8 * p = (Uint8*)dest->pixels + ftcpX*dest->format->BytesPerPixel + ftcpY*dest->pitch;
 		if(palc > 7) //normal color
 		{
-			ColorPutter<bpp, 0>::PutColor(p, color.R, color.G, color.B);
+			ColorPutter<bpp, 0>::PutColor(p, color.r, color.g, color.b);
 		}
 		else if((yellowBorder || blueBorder) && (palc == 6 || palc == 7)) //selection highlight
 		{
@@ -323,9 +323,9 @@ inline void CCreatureAnimation::putPixel(
 		else if (palc == 5) //selection highlight or transparent
 		{
 			if(blueBorder)
-				ColorPutter<bpp, 0>::PutColor(p, color.B, color.G - 0xf0 + animCount, color.R - 0xf0 + animCount); //shouldn't it be reversed? its bgr instead of rgb
+				ColorPutter<bpp, 0>::PutColor(p, color.b, color.g - 0xf0 + animCount, color.r - 0xf0 + animCount); //shouldn't it be reversed? its bgr instead of rgb
 			else if (yellowBorder)
-				ColorPutter<bpp, 0>::PutColor(p, color.R - 0xf0 + animCount, color.G - 0xf0 + animCount, color.B);
+				ColorPutter<bpp, 0>::PutColor(p, color.r - 0xf0 + animCount, color.g - 0xf0 + animCount, color.b);
 		}
 		else //shadow
 		{

+ 2 - 2
client/BattleInterface/CCreatureAnimation.h

@@ -15,7 +15,7 @@
  *
  */
 
-struct BMPPalette;
+struct SDL_Color;
 class CIntObject;
 
 /// Class which manages animations of creatures/units inside battles
@@ -36,7 +36,7 @@ private:
                 SDL_Surface * dest,
                 const int & ftcpX,
                 const int & ftcpY,
-                const BMPPalette & color,
+                const SDL_Color & color,
                 const ui8 & palc,
                 const bool & yellowBorder,
 				const bool & blueBorder,

+ 1 - 1
client/CCreatureWindow.cpp

@@ -555,7 +555,7 @@ void CCreatureWindow::showAll()
 
 	if (upgradeOptions.size() && (type == COMMANDER_LEVEL_UP && upgradeOptions[selectedOption] >= 100)) //add frame to selected skill
 	{
-		int index = selectedOption - selectableSkills.size(); //this is screwed
+//		int index = selectedOption - selectableSkills.size(); //this is screwed
 //*		CSDL_Ext::drawBorder(to, Rect::around(selectableBonuses[index]->pos), int3(Colors::METALLIC_GOLD.r, Colors::METALLIC_GOLD.g, Colors::METALLIC_GOLD.b)); 
 	}
 }

+ 11 - 9
client/CMT.cpp

@@ -77,7 +77,7 @@ static bool gOnlyAI = false;
 
 static bool ermInteractiveMode = false; //structurize when time is right
 void processCommand(const std::string &message);
-static void setScreenRes(int w, int h, int bpp, bool fullscreen, bool resetVideo=true);
+//static void setScreenRes(int w, int h, int bpp, bool fullscreen, bool resetVideo=true);
 void dispose();
 void playIntro();
 static void listenForEvents();
@@ -252,7 +252,7 @@ int main(int argc, char* argv[])
 	}
 
 	//Set environment vars to make window centered. Sometimes work, sometimes not. :/
-	putenv("SDL_VIDEO_CENTERED=center");
+	putenv((char*)"SDL_VIDEO_CENTERED=center");
 	//putenv("SDL_VIDEO_WINDOW_POS");
 
 	// Have effect on X11 system only (Linux).
@@ -308,14 +308,16 @@ int main(int argc, char* argv[])
 	tlog0 <<"\tInitializing screen: "<<pomtime.getDiff() << std::endl;
 
 	// Initialize video
-#if DISABLE_VIDEO
-	CCS->videoh = new CEmptyVideoPlayer;
-#else
-	if (!vm.count("disable-video"))
-		CCS->videoh = new CVideoPlayer;
-	else
+
+//TODO: video support for OpenGL
+//#if DISABLE_VIDEO
+//	CCS->videoh = new CEmptyVideoPlayer;
+//#else
+//	if (!vm.count("disable-video"))
+//		CCS->videoh = new CVideoPlayer;
+//	else
 		CCS->videoh = new CEmptyVideoPlayer;
-#endif
+//#endif
 
 	tlog0<<"\tInitializing video: "<<pomtime.getDiff()<<std::endl;
 

+ 14 - 2
client/CMakeLists.txt

@@ -2,7 +2,7 @@ project(vcmiclient)
 cmake_minimum_required(VERSION 2.6)
 
 include_directories(${CMAKE_HOME_DIRECTORY} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_HOME_DIRECTORY}/lib)
-include_directories(${SDL_INCLUDE_DIR} ${SDLIMAGE_INCLUDE_DIR} ${SDLMIXER_INCLUDE_DIR} ${SDLTTF_INCLUDE_DIR})
+include_directories(${SDL_INCLUDE_DIR} ${SDLIMAGE_INCLUDE_DIR} ${SDLMIXER_INCLUDE_DIR} ${SDLTTF_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR})
 include_directories(${Boost_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
 
 set(client_SRCS
@@ -18,6 +18,18 @@ set(client_SRCS
         UIFramework/Geometries.cpp
         UIFramework/CCursorHandler.cpp
         UIFramework/SDL_Extensions.cpp
+        UIFramework/GL2D.cpp
+        UIFramework/GL2D.h
+        Gfx/Animations.cpp
+        Gfx/Animations.h
+        Gfx/CPaletteRGBA.cpp
+        Gfx/CPaletteRGBA.h
+        Gfx/FilesHeaders.h
+        Gfx/Images.cpp
+        Gfx/Images.h
+        Gfx/ImgMakers.cpp
+        Gfx/Manager.cpp
+        Gfx/Manager.h
         AdventureMapClasses.cpp
         CAdvmapInterface.cpp
         CAnimation.cpp
@@ -94,7 +106,7 @@ else()
     add_executable(vcmiclient ${client_SRCS})
 endif()
 
-target_link_libraries(vcmiclient vcmi ${Boost_LIBRARIES} ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${SDLMIXER_LIBRARY} ${SDLTTF_LIBRARY} ${ZLIB_LIBRARIES} ${FFMPEG_LIBRARIES} ${RT_LIB} ${DL_LIB})
+target_link_libraries(vcmiclient vcmi ${Boost_LIBRARIES} ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${OPENGL_LIBRARIES} ${SDLMIXER_LIBRARY} ${SDLTTF_LIBRARY} ${ZLIB_LIBRARIES} ${FFMPEG_LIBRARIES} ${RT_LIB} ${DL_LIB})
 
 install(TARGETS vcmiclient DESTINATION ${BIN_DIR})
 

+ 4 - 4
client/CPreGame.cpp

@@ -240,7 +240,7 @@ CMenuScreen::CMenuScreen(const JsonNode& configNode):
 	{
 //*		if (background->bg->format->palette)
 //*			background->convertToScreenBPP();
-		background->scaleTo(Point(screen->w, screen->h));
+//*		background->scaleTo(Point(screen->w, screen->h));
 	}
 
 	pos = background->center();
@@ -2031,7 +2031,7 @@ void InfoCard::showAll()
 
 			//difficulty
 			assert(SEL->current->mapHeader->difficulty <= 4);
-			std::string &diff = CGI->generaltexth->arraytxt[142 + SEL->current->mapHeader->difficulty];
+//			std::string &diff = CGI->generaltexth->arraytxt[142 + SEL->current->mapHeader->difficulty];
 //*			printAtMiddleLoc(diff, 62, 472, FONT_SMALL, Colors::WHITE, to);
 
 			//selecting size icon
@@ -3330,7 +3330,7 @@ void CBonusSelection::show()
 	mapDesc->showAll(); //showAll because CTextBox has no show()
 
 	//map size icon
-	int temp;
+/*	int temp;
 	switch (ourHeader->width)
 	{
 	case 36:
@@ -3348,7 +3348,7 @@ void CBonusSelection::show()
 	default:
 		temp=4;
 		break;
-	}
+	}*/
 //*	blitAtLoc(sizes->ourImages[temp].bitmap, 735, 26, to);
 
 	//flags

+ 1 - 1
client/CSpellWindow.cpp

@@ -828,7 +828,7 @@ void CSpellWindow::SpellArea::showAll()
 	if(mySpell < 0)
 		return;
 
-	const CSpell * spell = mySpell.toSpell();
+//	const CSpell * spell = mySpell.toSpell();
 
 //*	blitAt(owner->spells->ourImages[mySpell].bitmap, pos.x, pos.y, to);
 //*	blitAt(owner->schoolBorders[owner->selectedTab >= 4 ? whichSchool : owner->selectedTab]->ourImages[schoolLevel].bitmap, pos.x, pos.y, to); //printing border (indicates level of magic school)

+ 2 - 2
client/GUIClasses.cpp

@@ -5260,8 +5260,8 @@ CPuzzleWindow::CPuzzleWindow(const int3 &GrailPos, double discoveredRatio):
 
 void CPuzzleWindow::showAll()
 {
-	int3 moveInt = int3(8, 9, 0);
-	Rect mapRect = genRect(544, 591, pos.x + 8, pos.y + 7);
+//	int3 moveInt = int3(8, 9, 0);
+//	Rect mapRect = genRect(544, 591, pos.x + 8, pos.y + 7);
 /*
 	CGI->mh->terrainRect
 		(grailPos - moveInt, adventureInt->anim,

+ 8 - 4
client/Gfx/Animations.h

@@ -43,7 +43,10 @@ public:
 };
 
 
-#pragma warning(disable : 4200)
+#ifdef _MSC_VER
+	#pragma warning(disable : 4200)
+	#pragma warning(disable : 4291)
+#endif
 
 class CPalettedAnimation : CAnimation
 {
@@ -54,17 +57,18 @@ class CPalettedAnimation : CAnimation
 protected:
 	CPalettedAnimation(const SH3DefFile& def, size_t fileSize);
 
-#pragma warning(disable : 4291)
 	inline void* operator new(size_t size, ui32 frCount) {
 		return ::operator new(size + frCount * sizeof(void*));
 	}
-#pragma warning(default : 4291)
 
 public:
 	virtual ~CPalettedAnimation();
 	virtual CImage* getFrame(ui32 fnr);
 };
 
-#pragma warning(default : 4200)
+#ifdef _MSC_VER
+	#pragma warning(default : 4200)
+	#pragma warning(default : 4291)
+#endif
 
 }

+ 5 - 1
client/Gfx/FilesHeaders.h

@@ -12,8 +12,10 @@ namespace Gfx
 
 #define SELF_ADDR reinterpret_cast<const ui8*>(this)
 
+#ifdef _MSC_VER
 #pragma pack(1)
 #pragma warning(disable : 4200)
+#endif
 
 struct SH3PcxFile
 {
@@ -50,7 +52,7 @@ struct SH3DefBlock {
 	ui32 unknown2;
 	char names[][13];	// [entriesCount][13] - array of frames names
 
-	inline const ua_ui32_ptr offsets() const {
+	inline ua_ui32_ptr offsets() const {
 		return (ua_ui32_ptr)(names + SDL_SwapLE32(entriesCount));
 	}	// array of offsets of frames
 };
@@ -74,8 +76,10 @@ struct SH3DefFile {
 	}
 };
 
+#ifdef _MSC_VER
 #pragma warning(default : 4200)
 #pragma pack()
+#endif
 
 #undef SELF_ADDR
 }

+ 6 - 6
client/UIFramework/CIntObjectClasses.cpp

@@ -1277,7 +1277,7 @@ void CBoundedLabel::showAll()
 	int lineHeight =  f->getLineHeight();
 	int lineCapacity = pos.h / lineHeight;
 
-	int dy = f->getLineHeight(); //line height
+//	int dy = f->getLineHeight(); //line height
 	int base_y = pos.y;
 	if(alignment == CENTER)
 		base_y += std::max((pos.h - maxH)/2,0);
@@ -1365,8 +1365,8 @@ void CTextBox::showAll()
 {
 	CIntObject::showAll();
 
-	const IFont * f = graphics->fonts[font];
-	int dy = f->getLineHeight(); //line height
+//	const IFont * f = graphics->fonts[font];
+//	int dy = f->getLineHeight(); //line height
 	int base_y = pos.y;
 
 	if (alignment == CENTER)
@@ -1380,8 +1380,8 @@ void CTextBox::showAll()
 		const std::string &line = lines[i + firstLineToPrint];
 		if(!line.size()) continue;
 
-		int width = pos.w + (slider ? (slider->pos.w) : 0);
-		int x = pos.x + int(alignment) * width / 2;
+//		int width = pos.w + (slider ? (slider->pos.w) : 0);
+//		int x = pos.x + int(alignment) * width / 2;
 
 //*		blitLine(to, Point(x, base_y + i * dy), line);
 	}
@@ -1519,7 +1519,7 @@ CTextInput::CTextInput(const Rect &Pos, SDL_Surface *srf)
 	captureAllKeys = true;
 	OBJ_CONSTRUCTION;
 	bg = new CPicture(Pos, 0, true);
-	Rect hlp = Pos;
+//	Rect hlp = Pos;
 /*	if(srf)
 		CSDL_Ext::blitSurface(srf, &hlp, *bg, NULL);
 	else

+ 1 - 1
client/UIFramework/GL2D.cpp

@@ -197,7 +197,7 @@ void attachToCurrentThread()
 	HDC hdc = GetDC(wmInfo.window);
 	wglMakeCurrent(hdc, wmInfo.hglrc);
 #elif _GLX
-	if (!glXMakeCurrent(wmInfo.info.x11.display, info.info.x11.window, glxCtx))
+	if (!glXMakeCurrent(wmInfo.info.x11.display, wmInfo.info.x11.window, glxCtx))
 	{
 		throw std::runtime_error("attachToCurrentThread: glXMakeCurrent failed\n");
 	}

+ 1 - 1
client/mapHandler.cpp

@@ -464,7 +464,7 @@ void CMapHandler::terrainRect( int3 top_tile, ui8 anim, const std::vector< std::
 	for (size_t bx = 0; bx < dx; bx++, srx+=32)
 	{
 		// Skip column if not in map
-		if (top_tile.x+bx < 0 || top_tile.x+bx >= sizes.x)
+		if (top_tile.x+si32(bx) < 0 || top_tile.x+bx >= sizes.x)
 			continue;
 
 		sry = sry_init;