jack872

Member
  • Content count

    12
  • Joined

  • Last visited

Community Reputation

156 Neutral

About jack872

  • Rank
    Member
  1. Hello guys! I made a game some years ago, a really old one using DX9 2004 and I'm trying to update it to the latest DX9. I managed to compile it with visual2010 but there are some strange behaviours ingame, most of the textures are black. I've checked more and more times and the only thing I found wrong is that LockRect returns D3DERR_INVALIDCALL but I can't understand why.   Please, some suggestions are appreciated.
  2. hello guys, I'm writing a game using DirectX9, I've always used my new pc (with a nvidia graphic card) to write the code and I hadn't any problem until I moved the code/binaries to my old computer with a ATI Radeon HD 4870:     It doesn't even render the world, all you can see is just these grey triangles. At the beginning I thought they were driver issues but then I relaized they were not (I updated them). The code is huge as it is a 3D game and since I'm debugging it for about a week without finding the problem, I'd like some suggestions. what can it be caused to? when does this happen? please, I need to fix this as soon as possibile.
  3. Progressive Sin Wave

    Thank you very much, you were right. Also, the casting from float to int amplified the problem. Now I've changed my constants and used a float dt instead of an integer and works pretty good. :) 
  4. Progressive Sin Wave

    Hello there, I'm trying to implement the water effect using the gamedev article about Hooke springs (http://gamedev.tutsplus.com/tutorials/implementation/make-a-splash-with-2d-water-effects/), but I wanted to add a sine wave generator to keep the waves moving. So I started writing a test code for generating a progressive sine wave: Water::Water(uint32 uiPoints) { m_points.resize(uiPoints); for (size_t i = 0; i < uiPoints; ++i) { m_points[i].p[0] = (i+1.f) / uiPoints * WIDTH; m_points[i].p[1] = 0.f; m_points[i].speed[1] = 0.f; } TimerSystem::getInstance().addTickable(this); } void Water::tick(uint32 dt) { m_uiDt += dt; // T = 2PI/w = 2PI*f uint32 T = static_cast<uint32>(Math::TWO_PI/w_constant*1000.f); // (in ms) if (m_uiDt >= T) m_uiDt -= T; // Y(x, t) = A*sin(k*x - w*t) float t = m_uiDt / 1000.f; for (size_t i = 0; i < m_points.size(); ++i) m_points[i].p[1] = amplitude * std::sinf(k_constant*m_points[i].p[0] - w_constant*t); } void Water::render() { // translate Math::Vector2f pos(0.f, Y_OFFSET); for (size_t i = 0; i < m_points.size(); ++i) Graphics::Renderer::getInstance().drawFillCircle(pos+m_points[i].p, 2.f, Math::Colorf::RED); } As far as I remember the formula is this one (long time I do not open a math book) but I started to render the points and I noticed that it's like generating 2 different waves:   I made the springs and the particles without any problem but I can't get the sine wave working (the easiest thing I know, so funny), what's wrong? Thanks in advice. :)
  5. Thanks unbird, I've fixed that part of code, now it doesn't render anything (or at least I can't see it). Between, yes, I've compiled the sample and works quite well....I'm using the same states but doesn't work anyway in the game. Well, to be honest, it works at the beginning on the video intro, but when the game gets into it menu, starts to give me these issues. The problem is I don't know what states the game is changing. I really don't know what to do :( Didn't do so many changes into the code, just added two lines here HRESULT myIDirect3DDevice9::Present(CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) { if (m_pStateBlock[0] && m_pStateBlock[1]) { D3DXMATRIX matView, projection; D3DXMatrixIdentity(&matView); Rocket::Core::Vector2i size = RocketGUI::getInstance().getSize(); m_pIDirect3DDevice9->SetTransform(D3DTS_VIEW, &matView); D3DXMatrixOrthoOffCenterLH(&projection, .0f, (float)size.x, (float)size.y, .0f, -1.f, 1.f); m_pIDirect3DDevice9->SetTransform(D3DTS_PROJECTION, &projection); m_pStateBlock[1]->Capture(); m_pStateBlock[0]->Apply(); RocketGUI::getInstance().render(); m_pStateBlock[1]->Apply(); } HRESULT hRes = m_pIDirect3DDevice9->Present(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion); return hRes; } And enabled the alpha-blending (like the sample https://github.com/lloydw/libRocket/blob/master/Samples/basic/directx/src/main.cpp)   void myIDirect3DDevice9::saveStates() { Utils::debug(LOGGER_DEBUG, "Saving DX states..."); HRESULT rs; rs = m_pIDirect3DDevice9->CreateStateBlock(D3DSBT_ALL, m_pStateBlock); CDAssert (rs != D3D_OK, (rs == D3DERR_OUTOFVIDEOMEMORY) ? "CreateStateBlock error: out of video memory" : "CreateStateBlock error"); rs = m_pIDirect3DDevice9->CreateStateBlock(D3DSBT_ALL, m_pStateBlock+1); CDAssert (rs != D3D_OK, (rs == D3DERR_OUTOFVIDEOMEMORY) ? "CreateStateBlock error: out of video memory" : "CreateStateBlock error"); m_pStateBlock[1]->Capture(); // Z Buffer states m_pIDirect3DDevice9->SetRenderState(D3DRS_ZENABLE, FALSE); m_pIDirect3DDevice9->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); m_pIDirect3DDevice9->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL); // Alpha states m_pIDirect3DDevice9->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); m_pIDirect3DDevice9->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_ALWAYS); m_pIDirect3DDevice9->SetRenderState(D3DRS_ALPHAREF, 0); m_pIDirect3DDevice9->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); // Blending states m_pIDirect3DDevice9->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); m_pIDirect3DDevice9->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); // Stencil buffer states m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILENABLE, FALSE); m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP); m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP); m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP); m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS); m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILREF, 0); m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILMASK, 0xffffffff); m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILWRITEMASK, 0xffffffff); m_pIDirect3DDevice9->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); m_pIDirect3DDevice9->SetRenderState(D3DRS_LIGHTING, FALSE); // Sampler states m_pIDirect3DDevice9->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); m_pIDirect3DDevice9->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); // Texture states m_pIDirect3DDevice9->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); m_pIDirect3DDevice9->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); m_pIDirect3DDevice9->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); m_pIDirect3DDevice9->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); m_pIDirect3DDevice9->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); m_pStateBlock[0]->Capture(); m_pStateBlock[1]->Apply(); Utils::debug(LOGGER_DEBUG, "DX states saved."); }
  6.   just tried right now, doesn't work. It doesn't get translated anymore but it is still grey.
  7. This is the way I set the states: void myIDirect3DDevice9::saveStates() { Utils::debug(LOGGER_DEBUG, "Saving DX states...");   HRESULT rs; rs = m_pIDirect3DDevice9->CreateStateBlock(D3DSBT_ALL, m_pStateBlock); CDAssert (rs != D3D_OK, (rs ==  D3DERR_OUTOFVIDEOMEMORY) ? "CreateStateBlock error: out of video memory" : "CreateStateBlock error"); rs = m_pIDirect3DDevice9->CreateStateBlock(D3DSBT_ALL, m_pStateBlock+1); CDAssert (rs != D3D_OK, (rs ==  D3DERR_OUTOFVIDEOMEMORY) ? "CreateStateBlock error: out of video memory" : "CreateStateBlock error");   m_pStateBlock[1]->Capture();   // Z Buffer states m_pIDirect3DDevice9->SetRenderState(D3DRS_ZENABLE, FALSE); m_pIDirect3DDevice9->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); m_pIDirect3DDevice9->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);   // Alpha states m_pIDirect3DDevice9->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); m_pIDirect3DDevice9->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_ALWAYS); m_pIDirect3DDevice9->SetRenderState(D3DRS_ALPHAREF, 0); m_pIDirect3DDevice9->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);   // Blending states m_pIDirect3DDevice9->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); m_pIDirect3DDevice9->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ZERO);   // Stencil buffer states m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILENABLE, FALSE); m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP); m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP); m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP); m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS); m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILREF, 0); m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILMASK, 0xffffffff); m_pIDirect3DDevice9->SetRenderState(D3DRS_STENCILWRITEMASK, 0xffffffff); m_pIDirect3DDevice9->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); m_pIDirect3DDevice9->SetRenderState(D3DRS_LIGHTING, FALSE);   // Sampler states m_pIDirect3DDevice9->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); m_pIDirect3DDevice9->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);   // Texture states m_pIDirect3DDevice9->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); m_pIDirect3DDevice9->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); m_pIDirect3DDevice9->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); m_pIDirect3DDevice9->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); m_pIDirect3DDevice9->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);   m_pStateBlock[0]->Capture(); m_pStateBlock[1]->Apply();   Utils::debug(LOGGER_DEBUG, "DX states saved."); }   This is the rendering: HRESULT myIDirect3DDevice9::Present(CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) { if (m_pStateBlock[0] && m_pStateBlock[1])  { m_pStateBlock[1]->Capture(); m_pStateBlock[0]->Apply(); RocketGUI::getInstance().render(); m_pStateBlock[1]->Apply(); }   HRESULT hRes = m_pIDirect3DDevice9->Present(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion); return hRes;  }  and this is how the librocket renderinterface works: void RenderInterfaceDirectX::RenderCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry, const Rocket::Core::Vector2f& translation) { D3DXMATRIX world_transform; D3DXMatrixTranslation(&world_transform, translation.x, translation.y, 0); g_pd3dDevice->SetTransform(D3DTS_WORLD, &world_transform);   RocketD3D9CompiledGeometry* d3d9_geometry = (RocketD3D9CompiledGeometry*) geometry;   g_pd3dDevice->SetFVF(vertex_fvf); g_pd3dDevice->SetStreamSource(0, d3d9_geometry->vertices, 0, sizeof(RocketD3D9Vertex)); g_pd3dDevice->SetIndices(d3d9_geometry->indices);   if (d3d9_geometry->texture != NULL) g_pd3dDevice->SetTexture(0, d3d9_geometry->texture); else g_pd3dDevice->SetTexture(0, NULL);   g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0,  d3d9_geometry->num_vertices, 0, d3d9_geometry->num_primitives); } But this is what I get As you can see it renders a big grey rectangle which gets rototranslated when the game camera moves
  8. Hello there, I'm trying to integrate libRocket to a game by revering engeering, I hooked the creation of the DirectX device with no problems, but I can't make the RenderInterface work properlly. I took a look at the DirectX sample given by the library to see how the states were setted, but looks like not all the states are showed, because when I try to render I just see grey boxes and the funny thing is they also gets translated when the game camera moves. I'm new with the DirectX, I've always used OpenGL so I really don't know what states are giving me this issue. For the camera part I think I just have to reset the view matrix, right? But for the states, could you please help me? Thanks in advice.
  9. OpenGL Map collisions

    [quote name='V-man' timestamp='1297436058' post='4772848'] For 2D collision detection, you can use normal physics engines like ODE (Open Dynamics), Newton, Bullet, Havok, PhysX. I don't get it. What does color have to do with collision? All you need is the position of objects. If you want to read the framebuffer, then it would be glReadPixels. [/quote] Mine is a racing game, and for the collisions I want to use a background image wich tells me where the vehicle can go. like this: http://t3.gstatic.com/images?q=tbn:ANd9GcRH2tXwuuLLYs8u6O2Wz2h4WEzLlT87N5ojRJoCTQT8mJEkI9ngsA&t=1 but I need something that retrives the color on a x,y position so I can easly compare with the one of the vehicle....
  10. OpenGL Map collisions

    [quote name='V-man' timestamp='1297302375' post='4772180'] GL is for rendering only. It is for sending commands to the GPU. [url="http://opengl.org/wiki/FAQ"]http://opengl.org/wiki/FAQ[/url] [/quote] thx for the info I'm using SDL for loading textures but I haven't found something useful on the website, is there any way to retrive and check the color on a determiated position of the image?
  11. Hello, I'm making a little 2d game, and I want to make the maps by loading 2 identical files, one for map drawing, 1 with particular colors for collisions definition. I know making tilesets would be easier but I do not like them at all. I'm wondering if it is possible to do something like this in OpenGL, if so please tell me wich functions I need to use thx
  12. Hello, I'm a newbie here so please be kind. I'm trying to make a little 2d videogame using SDL and OpenGL, but I'm having some problems on drawing the textures. I'm using the rotozoom fuction from SDL_gfx to resize the image, but some images, after resizing, are messed up. Here's my code: bool Texture::LoadTexture( string strFile, GLuint new_Width, GLuint new_Height ) { SDL_Surface *surface; GLenum texture_format; GLint nOfColors; if ( (surface = IMG_Load(strFile.c_str())) ) { if ( (surface->w & (surface->w - 1)) != 0 ) { printf( "warning: image's width is not a power of 2\n" ); } if ( (surface->h & (surface->h - 1)) != 0 ) { printf( "warning: image's height is not a power of 2\n" ); } nOfColors = surface->format->BytesPerPixel; if( nOfColors == 4 ) { if( surface->format->Rmask == 0x000000ff ) texture_format = GL_RGBA; else texture_format = GL_BGRA; } else if( nOfColors == 3 ) { if( surface->format->Rmask == 0x000000ff ) texture_format = GL_RGB; else texture_format = GL_BGR; } else { printf( "warning: the image is not truecolor.. this will probably break\n" ); return false; } surface = rotozoomSurfaceXY( surface, 0, 1, 1, 1 ); glGenTextures( 1, &texture ); glBindTexture( GL_TEXTURE_2D, texture ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, texture_format, GL_UNSIGNED_BYTE, surface->pixels ); width = (GLfloat)surface->w; height = (GLfloat)surface->h; SDL_FreeSurface( surface ); return true; } printf( "SDL could not load image: %s\n", SDL_GetError() ); return false; } Drawing: void Texture::DrawTexture( GLfloat x, GLfloat y ) { if( !texture ) return; glTranslatef( (GLfloat)x, (GLfloat)y, 0 ); glBindTexture( GL_TEXTURE_2D, texture ); glBegin( GL_QUADS ); glTexCoord2d( 0, 0 ); glVertex2d( 0, 0 ); glTexCoord2d( 1, 0 ); glVertex2d( width, 0 ); glTexCoord2d( 1, 1 ); glVertex2d( width, height ); glTexCoord2d( 0, 1 ); glVertex2d( 0, height ); glEnd(); glLoadIdentity(); } this is a screen of what I get: http://yfrog.com/jpscreen1q0j I can't understand why! without the rotozoom istruction the drawing works fine. Can someone help me? SOLVED: I've just found the problem... it was the rotozoom function wich changes the format so I put this istruction before I get the texture_format. :} [Edited by - jack872 on December 10, 2010 12:20:23 PM]