• Content count

  • Joined

  • Last visited

Community Reputation

158 Neutral

About Kaezin

  • Rank
  1. error which has me stumped

    Quote:Original post by Sneftel Quote:Original post by Kaezin Try adding a default constructor to your cArmor class. Finky, don't do that. It's a bad idea, for a few reasons. Your real problem is that you're using assignment statements to initialize your member variables in your cPlayer constructor. Instead, use initialization lists. I stand corrected, and wish I had seen that and saved myself the embarrassment.
  2. error which has me stumped

    I'm dumb. [Edited by - Kaezin on May 11, 2007 3:04:20 PM]
  3. Thanks for the help. I knew the Lighting code was useless, it was just leftover from before and I didn't bother removing it :P The problem was that I was never setting wvp, like you said. I was used to working with shaders using EffectEdit, and WORLDVIEWPROJECTION is what EffectEdit uses as a default. Thanks for the help, working fine now :P
  4. I've just begun to work with vertex shaders and I can't figure out why my shader results in nothing rendering. My vertex declaration like: D3DVERTEXELEMENT9 dec[3] = { {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION,0}, D3DDECL_END() }; DXUTGetD3DDevice()->CreateVertexDeclaration(dec,&vertexDec); D3DXCreateEffectFromFile(DXUTGetD3DDevice(),L"terrain.fx",NULL,NULL, D3DXSHADER_DEBUG | D3DXSHADER_SKIPOPTIMIZATION,NULL,&effect,NULL); effect->FindNextValidTechnique(NULL, &technique); And I render it like this: pd3dDevice->SetStreamSource( 0, vertexBuffer, 0, sizeof(VERTEX) ); pd3dDevice->SetVertexDeclaration(vertexDec); pd3dDevice->SetIndices(indexBuffer); pd3dDevice->SetMaterial( &material ); if (SUCCEEDED(effect->SetTechnique(technique))) { UINT numPasses; effect->Begin(&numPasses,0); for (UINT i=0;i<numPasses;i++) { effect->BeginPass(i); // Set the pass pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, numVertices,0, numPolygons ); effect->EndPass(); } effect->End(); } When I run the code as above, I get absolutely nothing shown at all. However, if I comment out all the effect and technique stuff and just do pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, numVertices,0, numPolygons ); then everything renders like normal. This is my shader fx file: float4x4 wvp : WORLDVIEWPROJECTION; // the format of our vertex data struct VS_OUTPUT { float4 Pos : POSITION; }; // Simple Vertex Shader - carry out transformation VS_OUTPUT VS(float4 Pos : POSITION) { VS_OUTPUT Out = (VS_OUTPUT)0; Out.Pos = mul(Pos, wvp); return Out; } technique terrainTechnique { pass p0 { Lighting = TRUE; VertexShader = compile vs_1_1 VS(); } } Everything renders fine when I view it in EffectEdit. Could anyone help me out? I don't know what I'm doing wrong. [Edited by - Kaezin on May 10, 2007 10:47:30 PM]
  5. Quote:Original post by Emmanuel Deloget unless Kaezin creates its terrain every frame (but you don't do that, right?) Nope, the top code I posted is only run once. Right now I don't care how long it takes me to initialize the data since I'm doing this mostly as a learning experience and care only about rendering speed. I am going to change it to use quadtrees though, since I want the terrain to get more advanced anyway :P Thanks for the help.
  6. I switched it to use a triangle list instead of a quad list, but that dropped the framerate even more (went from 40ish to 32ish). I don't know why that happened, since triangles are better than quads. The number of indices per tile went from 4 to 6 though, so maybe it has something to do with that. Anyway, here's the source with quads: #define Index( x, y ) ((y)*m_iWidth + (x)) CTerrain::CTerrain( ... ) { m_iWidth = 256; m_iHeight = 256; for(int i = 0; i < NUM_GT; i++) m_iNumTiles[i]=0; m_pVertices = new GLfloat[m_iWidth * m_iHeight * 3]; m_pNormals = new GLfloat[m_iWidth * m_iHeight * 3]; /* Type of ground at each vertex */ m_iType = new int[ m_iWidth * m_iHeight ]; float *fHeight = new float[ m_iWidth * m_iHeight ]; memset( fHeight, 0, m_iWidth * m_iHeight * sizeof(float) ); /* Do my random heightmap generation */ ... /* Generate the normals */ CVector3 *vNormals = new CVector3[ m_iWidth * m_iHeight]; int *iVertexCount = new int[ m_iWidth * m_iHeight]; memset( iVertexCount, 0, m_iWidth * m_iHeight * sizeof(int) ); /* Loop through all the faces and add the normals */ CVector3 a,b,c,d,n; int k = 0; for(int y = 0; y < m_iHeight - 1; y++) { for(int x = 0; x < m_iWidth - 1; x++) { a = CVector3((float)x, fHeight[x + y*m_iWidth], (float)y); b = CVector3((float)x, fHeight[x + (y+1)*m_iWidth], (float)(y+1)); c = CVector3((float)(x+1), fHeight[x + 1 + y*m_iWidth], (float)y); n = CalculateNormal(a,b,c); vNormals[x + y*m_iWidth] += n; vNormals[x + (y+1)*m_iWidth] += n; vNormals[x + 1 + y*m_iWidth] += n; iVertexCount[x + y*m_iWidth]++; iVertexCount[x + (y+1)*m_iWidth]++; iVertexCount[x + 1 + y*m_iWidth]++; d = CVector3((float)(x+1), fHeight[x + 1 + (y+1)*m_iWidth], (float)(y+1)); n = CalculateNormal(b,d,c); vNormals[x + 1 + (y+1)*m_iWidth] += n; vNormals[x + (y+1)*m_iWidth] += n; vNormals[x + 1 + y*m_iWidth] += n; iVertexCount[x + 1 + (y+1)*m_iWidth]++; iVertexCount[x + (y+1)*m_iWidth]++; iVertexCount[x + 1 + y*m_iWidth]++; k++; } } /* Normalize each vector and find its type */ for(int y = 0; y < m_iHeight; y++) { for(int x = 0; x < m_iWidth; x++) { k = x + y*m_iWidth; vNormals[k] = vNormals[k] * (1.0f / iVertexCount[k]); vNormals[k].Normalize(); m_pNormals[k*3] = vNormals[k][0]; m_pNormals[k*3 + 1] = vNormals[k][1]; m_pNormals[k*3 + 2] = vNormals[k][2]; m_pVertices[k*3] = (float)x * SCALE; m_pVertices[k*3 + 1] = fHeight[k] * SCALE; m_pVertices[k*3 + 2] = (float)y * SCALE; /* All grass just for testing */ m_iType[k] = GT_GRASS; m_iNumTiles[GT_GRASS]++; } } /* Terrain is complete, now find out the proper indices */ for( int i = 0; i < NUM_GT; i++) { m_pIndices[i] = new GLuint[ m_iNumTiles[i]*4 ]; k = 0; for(int y = 0; y < m_iHeight - 1; y++) { for(int x = 0; x < m_iWidth - 1; x++) { if( m_iType[ Index(x,y) ] == i ) { m_pIndices[i][k] = Index(x,y); m_pIndices[i][k+1] = Index(x,y+1); m_pIndices[i][k+2] = Index(x+1,y+1); m_pIndices[i][k+3] = Index(x+1,y); k += 4; } } } } delete[] fHeight; delete[] vNormals; delete[] iVertexCount; /* Lighting stuff */ ... } void CTerrain::Draw() { glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer( 3, GL_FLOAT, 0, m_pVertices ); glNormalPointer( GL_FLOAT, 0, m_pNormals ); for(int k = 0; k < NUM_GT; k++) { glDrawElements( GL_QUADS, m_iNumTiles[k]*4, GL_UNSIGNED_INT, m_pIndices[k] ); } } Thanks for any help. [Edited by - Kaezin on May 29, 2006 1:05:26 PM]
  7. Quote:Original post by phantom What kind of gfx card are you packing there Kaezin? Radeon 9600 XT, 256 MB.
  8. OpenGL Visibility

    Listen to zedzeek. While OpenGL won't draw anything not on the screen, it still requires an API call which can cumulatively get expensive, especially if the calls are essentially being ignored anyway.
  9. Right, I know it'd be more efficient to use a strip instead of a quad, but with the way that I'm going to be rendering things, I don't know if all the vertices and texture coordiantes will be laid out in a nice enough order to use a strip. Like you said though, it shouldn't be nearly as slow as it is =/
  10. I'm rendering a simple terrain mesh using vertex arrays, but it seems ridiculously slow for what I'm doing. Here's a quick breakdown of what I do: I want to eventually texture the map and blend together adjacent tiles that have differing textures. So to start off, I just broke down the quads into differing terrain types, grass if the height is above a certain value and water otherwise. I have one array for the normals and one array for my vertices. I also have an index array for each texture type that has to be drawn (which is just two for right now). When I initialize everything, I randomly generate the terrain and stick the tile coordinates in the appropriate index array. The vertices are laid out in row major order in my vertex array. Then when I want to draw everything, I just do this: glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer( 3, GL_FLOAT, 0, m_pVertices ); glNormalPointer( GL_FLOAT, 0, m_pNormals ); for(int k = 0; k < NUM_GROUNDTYPES; k++) { glDrawElements( GL_QUADS, m_iNumTiles[k]*4, GL_UNSIGNED_INT, m_pIndices[k] ); } Everything should be pretty self explanatory. m_iNumTiles[x] just keeps track of how many tiles were assigned to each ground type. Since a quad uses four vertices, I just multiply that by 4 to know how many vertices to process. m_pIndices is a 2D array that keeps track of the indices for each ground type. My question is, why is this so painstakingly slow? I'm not doing anything else at all in the program. I'm not even texturing anything and I only get 40ish FPS from my 256*256 mesh. If I make it 512 by 512, it drops to 25 FPS. Is it inefficient with regards to cache misses? Or am I just completely overlooking something?
  11. That's true, but I don't know in advance if all the vertices use the same texture coordinate since my light direction is constantly changing. Thanks though.
  12. Thanks guys, changing the texture parameters fixed it. There was no ambient or specular light set, only diffuse so I could keep things simple. I was using some old code and so my textures were set to repeat instead of clamp, which explains why I was getting the grey shade. Thanks again. [Edited by - Kaezin on March 14, 2006 1:27:34 PM]
  13. OpenGL Problem with terrain

    You said you think it may have to do with the normals, but you're not dealing with the normals at all in there, so I'm assuming there's no lighting either. I don't see anything wrong with the code you posted (there could be, I just don't see it) so I'm going to guess that the problem is somewhere else in the code. I'm don't know where though without seeing more of the code.
  14. I'm using a texture to implement fake phong shading, but I've come across a problem. I'll avoid the nitty gritty of what the phong shading is doing, since it is irrelevant to the what's going on. This is an example of what is happening when certain conditions are met: glTexCoord2f(0,0); glVertex3f(x1, y1, z1); glTexCoord2f(0,0); glVertex3f(x2, y2, z2); glTexCoord2f(0,0); glVertex3f(x3, y3, z3); I originally thought that the color at texture coordinate (0,0) would be used to texture the entire image, but I guess that's not the case. On my texture, the pixel at (0,0) is black and yet when I texture a triangle with that coordinate, I get an ugly grey result. When the texture isn't the same for all vertices, everything looks fine. Is this because the behavior in this case is generally undefined, or could there be something else wrong with my code?