Jump to content

  • Log In with Google      Sign In   
  • Create Account


Ahl

Member Since 02 Jul 2007
Offline Last Active Jun 01 2014 12:30 PM
-----

Posts I've Made

In Topic: Best method for a top down, side scrolling camera.

19 October 2012 - 07:52 PM

Alright, then I need to figure out what I'm doing wrong. I have the following:

void RenderScene()
{
std::sort (RenderList.begin(), RenderList.end(), SortRenderList);
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0f, 1.0f, 1.0f);
glLoadIdentity();
glTranslatef(MyCamera->GetPosX(), MyCamera->GetPosY(), MyCamera->GetPosZ());
uintptr_t LastKey =  (uintptr_t)-1;
uintptr_t LastMeshKey = (uintptr_t)-1;
uintptr_t LastTexKey = (uintptr_t)-1;
uintptr_t LastMatKey = (uintptr_t)-1;
for (RenderListIT = RenderList.begin(); RenderListIT != RenderList.end(); RenderListIT++)
{
  glPushMatrix();
  glLoadIdentity();
  glTranslatef((*RenderListIT)->Position->x, (*RenderListIT)->Position->y, (*RenderListIT)->Position->z);
 
  glScalef ((*RenderListIT)->Scale->x,  (*RenderListIT)->Scale->y,  (*RenderListIT)->Scale->z);
  glRotatef ((*RenderListIT)->Rotation->x, 1.0f, 0.0f, 0.0f);
  glRotatef ((*RenderListIT)->Rotation->y, 0.0f, 1.0f, 0.0f);
  glRotatef ((*RenderListIT)->Rotation->z, 0.0f, 0.0f, 1.0f);
  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_NORMAL_ARRAY);
  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  glEnableClientState(GL_COLOR_ARRAY);
  glEnable(GL_LIGHTING);
  if ((*RenderListIT)->Key != LastKey)
  {
   LastKey = (*RenderListIT)->Key;
   DrawCalls++;
   if ((*RenderListIT)->RenderMesh->Materials->Key != LastMatKey)
   {
    LastMatKey = (*RenderListIT)->RenderMesh->Materials->Key;
    if ((*RenderListIT)->RenderMesh->HasMaterials == true)
    {
	 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,  (*RenderListIT)->RenderMesh->Materials->Diffuse  );
	 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (*RenderListIT)->RenderMesh->Materials->Specular );
	 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,  (*RenderListIT)->RenderMesh->Materials->Ambient  );
	 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (*RenderListIT)->RenderMesh->Materials->Emission );
    }
   }
   if ((*RenderListIT)->RenderMesh->Key != LastMeshKey)
   {
    LastMeshKey = (*RenderListIT)->RenderMesh->Key;
    if (VBO_Support)
    {
	 glVertexPointer( 3, GL_FLOAT, sizeof(MyVertex), (GLvoid*) (*RenderListIT)->RenderMesh->VBO_Offset	 );
	 glNormalPointer(  GL_FLOAT, sizeof(MyVertex), (GLvoid*)((*RenderListIT)->RenderMesh->VBO_Offset+sizeof(float)*3) );
	 glTexCoordPointer( 2, GL_FLOAT, sizeof(MyVertex), (GLvoid*)((*RenderListIT)->RenderMesh->VBO_Offset+sizeof(float)*6) );
	 glColorPointer(  3, GL_FLOAT, sizeof(MyVertex), (GLvoid*)((*RenderListIT)->RenderMesh->VBO_Offset+sizeof(float)*8) );
    }
    else
    {
	 glVertexPointer( 3, GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData->x  );
	 glNormalPointer(  GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData->nx );
	 glTexCoordPointer( 2, GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData->u  );
	 glColorPointer(  3, GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData->a  );
    }
   }
   if ((*RenderListIT)->RenderMesh->Active->Key != LastTexKey)
   {
    LastTexKey = (*RenderListIT)->RenderMesh->Active->Key;
    if ((*RenderListIT)->RenderMesh->HasTexture == true)
    {
	 glEnable(GL_TEXTURE_2D);
	 glBindTexture(GL_TEXTURE_2D, (*RenderListIT)->RenderMesh->Active->TextureHandle);
    }
    else
    {
	 glDisable(GL_TEXTURE_2D);
    }
   }
  }
  glDrawArrays(GL_TRIANGLES, 0, (*RenderListIT)->RenderMesh->NumVerticies);
  glPopMatrix();
}
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisable(GL_LIGHTING);
}

And it's not moving the screen.

HELP!

In Topic: Best method for a top down, side scrolling camera.

18 October 2012 - 09:59 PM

I understand the camera class. My question is what OpenGL commands to use.

In Topic: Simple obj loader for OpenGl

20 September 2012 - 02:51 PM

I haven't been able to find one. I tried writing one myself which proved to be an exercise in futility. Assimp isn't incredibly difficult for simply loading models and once you get the wrapper done you can use any model type Assimp supports.

In Topic: VBO help...

19 September 2012 - 09:31 AM


struct MyVertex
{
float x, y, z;  // Vertex
float nx, ny, nz; // Normal
float u, v;   // Texcoords
float a, r, g, b; // Color
float padding[4];
};

Keep in mind that this is my data structure. An array of this is what is being loaded into the buffer, so the offset will be the same for all of the vertexs/normals/texcoords/etc per model.


No. If vertex data starts at offset 0 (the most common case in that scenario), then normal data starts at offset 0 + sizeof(float) * 3 and so on. Otherwise your normals are always your positions of the same vertex, your texture coordinates are just your (x, y) coordinates of the same vertex and your colors are the (x, y, z, nx) coordinates of the same vertex.

Setting the stride to sizeof(MyVertex) was correct but only half the problem.


Boom! That did it. Thank you very much!

In Topic: VBO help...

18 September 2012 - 07:10 PM

struct MyVertex
{
float x, y, z;  // Vertex
float nx, ny, nz; // Normal
float u, v;   // Texcoords
float a, r, g, b; // Color
float padding[4];
};

Keep in mind that this is my data structure. An array of this is what is being loaded into the buffer, so the offset will be the same for all of the vertexs/normals/texcoords/etc per model.

I figured out another problem. I had the stride set to 0. I set it to sizeof(MyVertex) and now my model is coming up properly. The textures are still wonky though. It's doing now what it was doing before when we figured out I had to do the whole &(*RenderListIT)->RenderMesh->VertexData->x bit.

PARTNERS