Strange behaviour with cygwin compile

Started by
2 comments, last by outRider 16 years, 8 months ago
Hello everyone, I'm having a bit of trouble with a c++ openGL chess game project. I compile using cygwin's g++ and the game runs great on my own pc and another friend's pc. However, some people running the game report the graphics window to be empty--all white--displaying nothing. I've only tested on 4 different pc's (all windows by the way), and the only trend I notice (which is barely a trend with only 4 computers) is that it works on AMD processors and not Intel's?? This may just be a coincidence though. I've never seen something like this and have no idea how to go about debugging the problem. I'm hoping someone has seen something like this before and can offer some advice. Here is the makefile I use, I'm guessing certain compile flags might have something to do with it:

INCLUDE = /home/Neemo/resource/inc/
LIBRARY = /home/Neemo/resource/lib/

CC = g++
CFLAGS = -I$(INCLUDE) -mno-cygwin

LOC_OBJ = Driver.o Board.o ChessWindow.o LocalPlayer.o MoveManager.o Piece.o RemotePlayer.o ChessConnection.o MenuScreen.o

# Rule to build Chess.exe
# -mwindows flag removes the background console window
chess: $(LOC_OBJ)
	$(CC) -o Chess $(CFLAGS) $(LIBRARY)*.o $^ -mwindows -lopengl32 -lglu32 -lgdi32 -lws2_32

# Special case object file
Driver.o: Driver.cpp
	$(CC) $(CFLAGS) -c $<

# Rule for building object files for classes
%.o : %.cpp %.h
	$(CC) $(CFLAGS) -c $<

clean:
	rm -f *.o *.exe *.stackdump

run:
	Chess
I hope this isn't too cryptic, I link to custom libraries in the $(LIBRARY) directory. All these object files are compiled the same way as above, with the -mno-cygwin flag. I don't have direct access to a computer that is having this problem, so I haven't tried compiling a version without the -mno-cygwin flag and just distributing the cygwin.dll file along with the executable. Could this solve the problem? I would post the source code for the game too, but the code base is rather large. I use quite a few classes (not even including whats in the library directory). Any help is appreciated here. I can send the executable to anyone who is willing to give it a try too. Thanks, neemo
Advertisement
You're probably doing something wrong with respect to initializing OpenGL. I doubt it has anything to do with differences in CPU, more likely differences in GPU/driver. Put the executable up somewhere and people will try it, and paste the code that creates the window, creates the rendering context, and possibly the drawing code.
Ok, I have uploaded the executable. It can be found here:
http://www.wikiupload.com/download_page.php?id=196116

Just unzip and double click the exe. Make sure you run it in the same directory as the Data folder.

And I uploaded a few source files, which I will do my best to explain below. They can be found here:
http://www.wikiupload.com/download_page.php?id=196119

Driver.cpp: Main entry point for the application
GLWindow.cpp: Encapsulates the gl context (yeah I know window is a bad name)
ChessWindow.cpp: Derived from GLWindow, makes the rendering routines specific
Window.cpp: Encapsulates a Microsoft Windows "Window"

Here is a bare bones look at the driver, I cut most of it out for simplicity (see the file for more details). An explanation follows below.

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)// EFFECTS: Main entry point for the application	// Create and show a window	win.create("Neemo Chess v1.1", NULL, IDI_CHESS, 0, WIN_WIDTH, WIN_HEIGHT);	win.show();	hWnd = win.getHandle();	// If the window wasn't created, quit program	if(!hWnd) exit(0);	// Create an openGL window	cw = new ChessWindow(hWnd);	cw->Resize(WIN_WIDTH, WIN_HEIGHT);	win.linkGLWindow(cw);							// Allow the window to resize the gl window}


The variable win is an object that encapsulates the application window. The way its created is all pretty standard stuff and the encapsulation is a pain in the ass that probably could have been done better. I tried to eliminate the cumbersome callback procedure. Anyways, for details see Window.cpp.

The cw variable is a "ChessWindow." It is derived from a base class called GLWindow. Essentially this class represents the openGL context. The name probably isn't the best choice since its not actually a window, but I found it intuitive for myself. All the initialization/drawing/game logic happens here. Its probably the most important file.

Ok, the important stuff. Here is where I create the openGL context and initialize some openGL states. As far as I know all this is standard opengl 1.2. This is in the GLWindow.cpp file:

GLWindow::GLWindow(HWND hwnd)// EFFECTS: Initialize rendering context and GL states{	m_hwnd = hwnd;						// Initialize window handle	m_hdc = GetDC(hwnd);				// Create a device context	SetupPixelFormat();					// Setup the pixel format	m_hrc = wglCreateContext(m_hdc);	// Create the rendering context	wglMakeCurrent(m_hdc, m_hrc);		// Make it current to the thread	InitializeStates();					// Initialize openGL states}void GLWindow::SetupPixelFormat()// EFFECTS: Set appropriate pixel format{	GLuint pixelFormat;	PIXELFORMATDESCRIPTOR pfd =	{		sizeof(PIXELFORMATDESCRIPTOR),	// size		1,								// version		PFD_SUPPORT_OPENGL |			// OpenGL window		PFD_DRAW_TO_WINDOW |			// render to window		PFD_DOUBLEBUFFER,				// support double-buffering		PFD_TYPE_RGBA,					// color type		32,								// prefered color depth		0, 0, 0, 0, 0, 0,				// color bits (ignored)		0,								// no alpha buffer		0,								// alpha bits (ignored)		0,								// no accumulation buffer		0, 0, 0, 0,						// accum bits (ignored)		16,								// depth buffer		0,								// no stencil buffer		0,								// no auxiliary buffers		PFD_MAIN_PLANE,					// main layer		0,								// reserved		0, 0, 0};						// no layer, visible, damage masks	pixelFormat = ChoosePixelFormat(m_hdc, &pfd);	SetPixelFormat(m_hdc, pixelFormat, &pfd);}void GLWindow::InitializeStates()// EFFECTS: Initialize OpenGL states{	glShadeModel(GL_SMOOTH);							// Enable smooth shading	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);				// Black background	glClearDepth(1.0f);									// Depth Buffer Setup	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Nicest perspective calculations	// Nicest looking antialiasing for all primitives	glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);	glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);	glHint(GL_LINE_SMOOTH_HINT,	GL_NICEST);	// Antialiasing for all primitives	glEnable(GL_POLYGON_SMOOTH);	glEnable(GL_POINT_SMOOTH);	glEnable(GL_LINE_SMOOTH);	glEnable(GL_TEXTURE_2D);		// Allow using 2D textures	glEnable(GL_DEPTH_TEST);		// Enable depth testing	glDepthFunc(GL_LEQUAL);			// Set the testing type	// Allow simpler coloring of materials	glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);	glEnable(GL_COLOR_MATERIAL);}


The constructor for the class gets the rendering context and sets up some states that I figured all derived classes should probably use. The HWND parameter comes from the Window object created in the driver file. Some more states are set in the setup of the ChessWindow derived class like face culling. To avoid making the post to long, take a look at ChessWindow.cpp and GLWindow.cpp side by side. Hopefully their relationship makes sense.

I apologize if any of the code is messy or hard to understand. If there is any confusion, i'll do my best to clear it up. Hopefully this helps diagnose the problem :D

neemo
Works for me.

Try getting rid of the white background brush, set to 0 instead.

This topic is closed to new replies.

Advertisement