Ogre722

Members
  • Content count

    17
  • Joined

  • Last visited

Community Reputation

100 Neutral

About Ogre722

  • Rank
    Member
  1. 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: [code] 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; [/code] 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?
  2. [quote name='KulSeran' timestamp='1302245597' post='4795854'] Only one thread can own the context at any one time. You have to lock out the other thread from taking the context from you mid operation. [/quote] What do you mean specifically by "lock out"? Does this mean that only one thread at a time can make opengl function calls?
  3. 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: [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; } [/code]
  4. OpenGL

    Quote:Original post by WhatEver You're getting what looks like z fighting. In your case, turning on back face culling should fix it. If not, look at the model and make sure you don't have double sided polygons. If you do delete the polygons you can't see, or never will see. Thank you, I would have never thought of that. after reading your message I took a look at the model, and this is what i found under the front faces: http://i713.photobucket.com/albums/ww140/ogre722/Untitled.png?t=1282622701 I was garbage left over from creating the model by just duplicating a cube.
  5. 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
  6. Quote:Original post by mhagain It's impossible to say without seeing some code. There are many things that could slow down your rendering, and that kind of performance definitely seems quite low given the poly counts you have. As a rough guess, given that you talk about discrete polygons, I am wondering if you're using glBegin/glEnd for each of those 20194 polys. But again, without seeing some code anything I might say is purely in the realms of speculation. Here is the pertinent code: The main draw method: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); cam.Render(); rs_AddLight(v3(0,5,0), v3(1,1,1), 0); rs_AddLight(v3(0,-5,0), v3(1,0,0), 1); shader.bind(); shader.passVar1i(1, "l[0]"); shader.passVar1i(1, "l[1]"); shader.passVar1i(1, "hasTex"); rs_DrawObj(&obj, &mat_obj); shader.passVar1i(0, "hasTex"); glPushMatrix(); glScalef(.5,.5,.5); rs_DrawObj(&light); glPopMatrix(); shader.unbind(); Here are the two rsDrawObj methods void rs_DrawObj(objModel* o) { SetDefMat(); glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); glCallList(o->object); glEnable(GL_TEXTURE_2D); } void rs_DrawObj(objModel* o, Material* m) { GLfloat d[] = { m->d_Col.x, m->d_Col.y, m->d_Col.z, 1 }; GLfloat s[] = { m->s_Col.x, m->s_Col.y, m->s_Col.z, 1 }; GLfloat a [] = { m->a_Col.x,m->a_Col.y,m->a_Col.z,1 }; glMaterialfv(GL_FRONT, GL_DIFFUSE, d); glMaterialfv(GL_FRONT, GL_SPECULAR, s); glMaterialfv(GL_FRONT, GL_AMBIENT, a); glMaterialf(GL_FRONT, GL_SHININESS, m->shine); if (m->color.texID != 0) { glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); glCallList(o->object); } else { glBindTexture(GL_TEXTURE_2D, m->ColorTexID); glCallList(o->object); glEnable(GL_TEXTURE_2D); } }
  7. 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
  8. Thank you to everyone who posted on this thread, all the suggestions were helpful. I was able to improve the performance of my loader and learn a few new things about programming and c++.
  9. 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.
  10. OpenGL

    Quote:Original post by karwosts I don't think you're doing the lighting calculations correctly. Quote: lightVector = gl_LightSource[0].position.xyz - gl_Vertex.xyz; If your model matrix is anything other than identity, this isn't going to work. Keep in mind gl_Vertex is always the exact same value, no matter how you rotate your head. Thats why your light always lights the same side of the object, because you're not supplying any rotation information into the calculation. The object rotates on the screen because you are rotating gl_Vertex with the model matrix. Your light is defined (I'm guessing) in view space, while your gl_Vertex is in model space, and it isn't legal to perform mathematical operations like this between coordinates in different spaces. You need to pick what space you want to do your calculations in: view space, world space, model space, these are all valid choices, but every value you use in the calculation must be in the same space. I think the easiest solution for you for this would be to make these modifications: vec3 normal = gl_NormalMatrix* gl_Normal; //Normal from model space to view space) lightVector = gl_LightSource[0].position.xyz - vec4(gl_ModelViewMatrix*gl_Vertex).xyz; The ftransform() function hides all of this from you for the vertices. Try to replace it with the real matrix calculations, it may help you understand better. Thank you for this explanation, you are correct and your solution fixed the problem I was having, it is greatly appreciated.
  11. OpenGL

    Quote:Original post by _OskaR Looks like one vector has wrong direction. U can do sth like vec3 lightVector = gl_LightSource[0].position.xyz - gl_Vertex.xyz; instead vec3 lightVector = gl_Vertex.xyz - gl_LightSource[0].position.xyz; I've corrected that and I am still having the same issue. It seems as though the initial position of the light is being taken into consideration, almost as if it were another independent light source as the other circles the model. Its difficult to see in the screenshots, but the back is always in shadow even after the light has changed position.
  12. I am experimenting with GLSL shaders. What I wanted to do is just create a simple shader that replicates the openGL lighting model and I can't seem to do it. I'm sure that this is a very noob question with a simple answer but I can't figure it out. Here is what the opengl render looks like: http://i713.photobucket.com/albums/ww140/ogre722/nonshader.png?t=1276329120 And this is what the GLSL render looks like: http://i713.photobucket.com/albums/ww140/ogre722/shader.png?t=1276329172 Based on this code: [Vertex Shader] varying vec4 diffuse; void main() { gl_Position = ftransform(); vec3 normal = gl_Normal; vec3 lightVector = vec3(0,0,5); lightVector = gl_LightSource[0].position.xyz - gl_Vertex.xyz; lightVector = normalize(lightVector); float nxDir = max(0.0, dot(normal, -lightVector)); diffuse = gl_LightSource[0].diffuse * nxDir; } [Fragment Shader] varying vec4 diffuse; void main() { gl_FragColor = gl_LightSource[0].ambient + diffuse; }
  13. Quote:Original post by karwosts You should definitely post code, I'm sure you can get some help here. You're right that its not a terribly efficient format to load, but this should be a one time hit when program loads and shouldn't effect your framerate. The methods you use to draw the data will matter a lot though. Are you by chance using immediate mode drawing (glBegin/glEnd)? This is a very slow method and should not be used, the proper method of drawing is to use Vertex Buffer Objects (VBO). I'm sure we can give more specific advice once we see your rendering code. I've been looking into this and I can't get it to work. could you show me how to implement this in the code i posted or show me a page that explains it?
  14. Quote:Original post by NumberXaero glBegin()/glEnd() is the slowest way you could be rendering this with opengl, look into vertexbuffer objects. The framerate doesnt have anything to do with the loader. I know that initial loading doesn't have much to do with the final framerate, but I figured I'd mention it since someone might know a better, more efficient way to get the data into memory.
  15. Quote:Original post by karwosts You should definitely post code, I'm sure you can get some help here. You're right that its not a terribly efficient format to load, but this should be a one time hit when program loads and shouldn't effect your framerate. The methods you use to draw the data will matter a lot though. Are you by chance using immediate mode drawing (glBegin/glEnd)? This is a very slow method and should not be used, the proper method of drawing is to use Vertex Buffer Objects (VBO). I'm sure we can give more specific advice once we see your rendering code. Okay, here is objLoader.h #include <gl/gl.h> #include <iostream> #include <fstream> #include <string> using namespace std; string getValues(char Char, string line); struct Vertex { float x, y, z; int indexNum; }; struct Normal { float x,y,z; int indexNum; }; struct texCoord { float U, V; int indexNum; }; struct Face { int v1, v2, v3, v4; int n1, n2, n3, n4; int uv1, uv2, uv3, uv4; Face operator = (const Face ¶m); }; class objModel { public: objModel(); bool Load(char* filename); void Draw(); private: Vertex *pVerts; Normal *pNorms; texCoord *pUVs; Face *pfaces; int nVerts, nNorms, nUVs, nFaces; char *filename; void getVert(string line, float &x, float &y, float &z); void getNorm(string line, float &x, float &y, float &z); void getUV(string line, float &x, float &y); Face getFace(string line); int fileLines(char* filename); void numVertNormUVFace(char *filename, int &verts, int &norms, int &UVs, int &faces); }; and here is objLoader.cpp #include "ObjLoader.h" objModel::objModel() { } 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(); } } 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) { filename = Filename; nVerts = nNorms = nUVs = nFaces = 0; string tmp; numVertNormUVFace(filename, nVerts, nNorms, nUVs, nFaces); cout << "In the file " << filename << " there are:" << endl; cout << nVerts << " Vertices." << endl; cout << nNorms << " Normals." << endl; cout << nUVs << " Texture Coordnates." << endl; cout << nFaces << " Polygons." << 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; ifstream file(filename); 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); pVerts[vLoop].indexNum = vLoop; vLoop++; } if (tmp[0] == 'v' && tmp[1] == 'n') { getNorm(tmp, pNorms[nLoop].x, pNorms[nLoop].y, pNorms[nLoop].z); pNorms[nLoop].indexNum = nLoop; nLoop++; } if (tmp[0] == 'v' && tmp[1] == 't') { getUV(tmp, pUVs[tLoop].U, pUVs[tLoop].V); pUVs[tLoop].indexNum = tLoop; tLoop++; } if (tmp[0] == 'f' && tmp[1] == ' ') { pfaces[fLoop] = getFace(tmp); fLoop++; } } file.close(); } return true; } void objModel::Draw() { glBegin(GL_QUADS); for (int f = 0; f < nFaces; f++) { glVertex3f(pVerts[pfaces[f].v1-1].x, pVerts[pfaces[f].v1-1].y, pVerts[pfaces[f].v1-1].z); glVertex3f(pVerts[pfaces[f].v2-1].x, pVerts[pfaces[f].v2-1].y, pVerts[pfaces[f].v2-1].z); glVertex3f(pVerts[pfaces[f].v3-1].x, pVerts[pfaces[f].v3-1].y, pVerts[pfaces[f].v3-1].z); glVertex3f(pVerts[pfaces[f].v4-1].x, pVerts[pfaces[f].v4-1].y, pVerts[pfaces[f].v4-1].z); } glEnd(); } Face Face::operator = (const Face ¶m) { n1 = param.n1; n2 = param.n2; n3 = param.n3; n4 = param.n4; v1 = param.v1; v2 = param.v2; v3 = param.v3; v4 = param.v4; uv1 = param.uv1; uv2 = param.uv2; uv3 = param.uv3; uv4 = param.uv4; return *this; } The code here is just enough so that i could load the model data into memory and render the verts onto the screen.