Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


Ogre722

Member Since 27 Apr 2010
Offline Last Active Mar 31 2012 06:38 PM

Topics I've Started

stuck key input caused by WM_KEYUP not being called

23 February 2012 - 08:28 PM

I have a problem with the WM_KEYUP message not being sent. I've had this problem ever since the first NeHe tutorials that I did when I first started out. I have had this problem across many different input management scheme's, so I don't think its my code that is directly responsible for this, but here it is anyway:

case WM_KEYDOWN:
			if (win_active)
				for (list<KeyInput>::iterator t = key_inputs.begin(); t != key_inputs.end(); ++t)
					(*t).PushKeyDown(ConvertKeyCode(wparam));
		return 0;
		case WM_KEYUP:
			if (win_active)
				for (list<KeyInput>::iterator t = key_inputs.begin(); t != key_inputs.end(); ++t)
					(*t).PushKeyUp(ConvertKeyCode(wparam));
		return 0;

What happens is every so often, a key is pressed down, the keydown message is sent. But when the key is released the keyup message is not sent and my program thinks the key has not been released. the only way to fix this is to press the key again to "unstick" the key. Does anyone know a way to fix this problem?

OpenGL Windows Multithreading Issue

07 April 2011 - 08:58 PM

I'm having trouble getting opengl to work in multiple threads on windows. I followed the sample code from the opengl wiki but Its simply not working for me.

I tried to generate and build a display list on my main thread and within the other thread, both with the same opengl configuration (2 contexts sharing lists). When on the main thread it works perfectly. When on the separate thread, it generates the id but seems to ignore all the commands associated with actually building the list.

I've monitored the processes memory usage during both trials and it is clear that the display list is never generated when called to do so in the other thread.

I've encountered this problem before and gave up on multi-threading opengl, I really want to get it to work this time. Any help is appreciated.

Here is the related code:
DWORD WINAPI Windows::thread_callback(void* arg)
{
	Windows* window = static_cast<Windows*> (arg);
	wglMakeCurrent(window->hdc, window->thd_hrc);

	while (!window->done)
    	window->ThreadLoop();

	if (!wglMakeCurrent(0,0))
    	error("Could not Thread context", "", "Shutdown Error").print();
	if (!wglDeleteContext(window->thd_hrc))
    	error("Could not delete thread context", "", "Shutdown Error").print();
}
// During Window creation...
	if (!(hdc=GetDC(hwd))                      	||
    	!(PixelFormat=ChoosePixelFormat(hdc,&pfd)) ||
    	!(SetPixelFormat(hdc,PixelFormat,&pfd))	||
    	!(hrc=wglCreateContext(hdc))   			||
    	!(thd_hrc=wglCreateContext(hdc)) )
	{
    	destroy_window();
    	return false;
	}

	if (!wglShareLists(hrc, thd_hrc))
	{
 		DWORD errorCode=GetLastError();
 		LPVOID lpMsgBuf;
 		FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
        	NULL, errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPTSTR) &lpMsgBuf, 0, NULL);
 		MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
 		LocalFree(lpMsgBuf);
 		wglDeleteContext(thd_hrc);
 		destroy_window();
 		return false;
	}

	if (!wglMakeCurrent(hdc, hrc))
	{
    	destroy_window();
    	return false;
	}

OpenGL artifacts

23 August 2010 - 02:21 AM

I can't seem to find the cause of this problem I have been having with my Space Invaders clone. With the models of the invaders I am getting weird artifacts that seem to be glitches in the rasterization process. I tested my graphics card (9800gt), commercial games don't get this issue and even other models work fine. The models are simple and were made in Blender. I'd say more but I can't think of anything else that could be causing the problem. I appreciate any comments or suggestions.

Here is a screen shot.
http://i713.photobucket.com/albums/ww140/ogre722/screenshot.jpg?t=1282569595

low framerate with my opengl code

11 July 2010 - 07:25 PM

I have created a small rendering system that is built around OpenGL. From the OpenGL gurus out there I'd like to know whether or not I should be expecting better frame rates than I have been getting based on scene complexity. I have two screen shots that were taken on my computer. one is of my code rendering a very reasonably sized scene and the other is of my computer running the source engine for comparison. I appreciate any comments or helpful suggestions offered.

http://i713.photobucket.com/albums/ww140/ogre722/scn.png?t=1278915361
The stats on this screen shot are:
210 frames per second
20194 total scene polygons (map + head)
rendered using a GLSL shader program

http://i713.photobucket.com/albums/ww140/ogre722/srcscn.png?t=1278915738

My System Specs are:
q6600 2.4ghz quad core cpu
9800gt gpu
4gb ram
5400rpm hard drive

Obj Loader Performance

14 June 2010 - 06:30 AM

I have created an obj loader for my rendering engine and I am not very satisfied with its performance. I compared it to the loader used by Blender3d and it is only slightly slower. But still, I want to use this to support real time rendering so I need it to be fast. The code is all inside a class, so I will show the functions:
Quote:


int objModel::fileLines(char* filename)
{
int size = 0;
string* line = new string;
ifstream inData;
inData.open(filename);
if (!inData)
return 0;
if (inData.is_open())
{
while (!inData.eof())
{
getline(inData, *line);
size++;
}
inData.close();
}
delete line;
return size;
}

void objModel::numVertNormUVFace(char *filename, int &verts, int &norms, int &UVs, int &faces)
{
ifstream data;
string tmp;
data.open(filename);
if (data.is_open())
{
while (!data.eof())
{
getline(data, tmp);
if(tmp[0] == 'v' && tmp[1] == ' ') { verts++; }
if(tmp[0] == 'v' && tmp[1] == 't') { UVs++; }
if(tmp[0] == 'v' && tmp[1] == 'n') { norms++; }
if(tmp[0] == 'f' && tmp[1] == ' ') { faces++; }
}
data.close();
}
if (verts < 1)
MessageBox(NULL, "Could not read obj file.", filename, MB_ICONERROR);

}

void objModel::getVert(string line, float &x, float &y, float &z)
{
string vString[3];
int c = 0;

for (int i = 2; i <= line.size(); i++)
{
if (line[i] == ' ')
{
c++;
}
else
{
vString[c].push_back(line[i]);
}
}

x = (float)atof(vString[0].c_str());
y = (float)atof(vString[1].c_str());
z = (float)atof(vString[2].c_str());
}

void objModel::getNorm(string line, float &x, float &y, float &z)
{
string vString[3];
int c = 0;

for (int i = 3; i <= line.size(); i++)
{
if (line[i] == ' ')
{
c++;
}
else
{
vString[c].push_back(line[i]);
}
}

x = (float)atof(vString[0].c_str());
y = (float)atof(vString[1].c_str());
z = (float)atof(vString[2].c_str());
}

void objModel::getUV(string line, float &x, float &y)
{
string vString[2];
int c = 0;

for (int i = 3; i <= line.size(); i++)
{
if (line[i] == ' ')
{
c++;
}
else
{
vString[c].push_back(line[i]);
}
}


x = (float)atof(vString[0].c_str());
y = (float)atof(vString[1].c_str());
}

Face objModel::getFace(string line)
{
string fString[4];
int c = 0;

for (int i = 2; i < line.size(); i++)
{
if (line[i] == ' ')
{
c++;
}
else
{
fString[c].push_back(line[i]);
}
}

string s1[3][4];

c = 0;

for (int x = 0; x < 4; x++)
{
for (int i = 0; i < fString[x].size(); i++)
{
if (fString[x].at(i) == '/')
{
c++;
}
else
{
s1[c][x].push_back(fString[x].at(i));
}
}
c = 0;
}

Face f;
f.v1 = atoi(s1[0][0].c_str());
f.v2 = atoi(s1[0][1].c_str());
f.v3 = atoi(s1[0][2].c_str());
f.v4 = atoi(s1[0][3].c_str());

f.uv1 = atoi(s1[1][0].c_str());
f.uv2 = atoi(s1[1][1].c_str());
f.uv3 = atoi(s1[1][2].c_str());
f.uv4 = atoi(s1[1][3].c_str());

f.n1 = atoi(s1[2][0].c_str());
f.n2 = atoi(s1[2][1].c_str());
f.n3 = atoi(s1[2][2].c_str());
f.n4 = atoi(s1[2][3].c_str());
return f;
}

bool objModel::Load(char* Filename, int meshType)
{
t1 = GetTickCount();
hasTexCoords = false;
hasNormals = false;
MeshType = meshType;
filename = Filename;
nVerts = nNorms = nUVs = nFaces = 0;
string tmp;
ifstream file(filename);
if (!file)
{
cout << endl << "could not load " << filename << endl;
return false;
}


numVertNormUVFace(filename, nVerts, nNorms, nUVs, nFaces);
cout << "Filename: " << filename << endl;
cout << "Verts: " << nVerts << endl;
cout << "Norms: " << nNorms << endl;
cout << "TexCoord: " << nUVs << endl;
cout << "Polygons: " << nFaces<< endl;

pVerts = new Vertex[nVerts];
pUVs = new texCoord[nUVs];
pNorms = new Normal[nNorms];
pfaces = new Face[nFaces];

int vLoop = 0;
int nLoop = 0;
int tLoop = 0;
int fLoop = 0;

if (file.is_open())
{
while (!file.eof())
{
getline(file, tmp);
if (tmp[0] == 'v' && tmp[1] == ' ')
{
getVert(tmp, pVerts[vLoop].x, pVerts[vLoop].y, pVerts[vLoop].z);
vLoop++;
}
if (tmp[0] == 'v' && tmp[1] == 'n')
{
hasNormals = true;
getNorm(tmp, pNorms[nLoop].x, pNorms[nLoop].y, pNorms[nLoop].z);
nLoop++;
}
if (tmp[0] == 'v' && tmp[1] == 't')
{
hasTexCoords = true;
getUV(tmp, pUVs[tLoop].U, pUVs[tLoop].V);
tLoop++;
}
if (tmp[0] == 'f' && tmp[1] == ' ')
{
pfaces[fLoop] = getFace(tmp);
fLoop++;
}
}
file.close();
}
t2 = GetTickCount();
cout << "ObjLoad: " << (t2-t1)*.001 << "s" << endl;
return true;
}

I will greatly appreciate any suggestions that can be given.

PARTNERS