Jump to content

  • Log In with Google      Sign In   
  • Create Account

Ogre722

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

Posts I've Made

In Topic: OpenGL Windows Multithreading Issue

08 April 2011 - 09:15 AM

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.


What do you mean specifically by "lock out"? Does this mean that only one thread at a time can make opengl function calls?

In Topic: OpenGL artifacts

23 August 2010 - 05:07 PM

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.

In Topic: low framerate with my opengl code

12 July 2010 - 09:23 AM

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);
}
}

In Topic: Obj Loader Performance

16 June 2010 - 05:39 AM

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++.

In Topic: GLSL Lighting Problem

14 June 2010 - 06:23 AM

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.

PARTNERS