Jump to content
  • Advertisement

-pete-

Member
  • Content count

    20
  • Joined

  • Last visited

Community Reputation

122 Neutral

About -pete-

  • Rank
    Member
  1. -pete-

    SDL Font help

    Thanks for the tips kman, I've changed the code slightly to be more like the documentation bool text::loadFont (SDL_Surface *screen) { if (TTF_Init() == -1) { return false; } TTF_Font *font; font = TTF_OpenFont ( "lazy.ttf", 16); if (!font) { printf ("TTF_OpenFont: %s\n", TTF_GetError()); // handle error } SDL_Surface *messageText; SDL_Color textColor = {255, 255, 255, 255}; messageText = TTF_RenderText_Solid( font, "Text to render goes in here", textColor); drawGFX (10, 10, messageText, screen); return true; } I've tried that but still nothing. Will printf actually work? I thought that I would have to do this to get any form of text to display? I only really want to get this setup for debugging so is there another method that I could use to display text?
  2. -pete-

    SDL Font help

    Hey guys please can someone help me out with this! I've being pulling my hair out for about 4 hours with it! So I'm following the tutorials over at lazyfoo about loading a font system in, I've had to slice it up a bit to go along with what is already in my code but I'm having a few problems, namely that it doesn't actually work [bawling] I don't get any compiler errors however it doesn't display the text. Here is the code that I am using at the moment: // class constructor text::text() { // Initialise TTF TTF_Init() == -1; } bool text::loadFont (SDL_Surface *screen) { // Load TTF font TTF_Font *font; if (font == NULL) { return false; } // create the surface for a message SDL_Surface *messageText; // set the font color to black (tried with white too but no joy) SDL_Color textColor = {0, 0, 0, 0}; // load the font font = TTF_OpenFont ( "lazy.ttf", 16); // assign the text to the surface messageText = TTF_RenderText_Solid( font, "why does this not render?", textColor); // use drawGFX to render the text drawGFX (10, 10, messageText, screenSurface); return true; } drawGFX is in a seperate visualisation class and it looks like this: void visualisation::drawGFX( int x, int y, SDL_Surface* source, SDL_Surface* destination ) { //Make a temporary rectangle to hold the offsets SDL_Rect offset; //Give the offsets to the rectangle offset.x = x; offset.y = y; //Blit the surface SDL_BlitSurface( source, NULL, destination, &offset ); } this works for blitting bitmaps and PNG files without a problem, doesn't anyone have any ideas as to what could possibly be wrong with it? Cheers for your help -pete-
  3. For the last few weeks I've being working on my final year uni project and I've finally finished coding. However I need some peeps to test it for me and I thought about you lucky folks for my testers (as well as anyone else who will have a go) The game is called GoBlue! and its being written to run on the DS. The aim of the game is to avoid as many of the enemy ships as possible by dragging the little blue sprite around. You can take out the enemies by tapping your stylus on them so its the old "risk and reward" tap enemies for points but if you health drops to zero you are dead sonny. Download it from http://www.lo-jen.com/pete/DS/GoBlue/GoBlue+Emu.zip everything is included including an emulator, to run it unzip the folder, run NO$GBA, browse to the goblue.ds file and click open. Bugs I know about at the moment are: 1. Having to restart system at end of game (press the numpad * to reset) 2. Graphical glitches after longer periods of play 3. The ludicrous difficulty XD 4. The enemies spawning right on top of you Please, please PLEASE! report anything else in this thread Cheers guys
  4. -pete-

    Need help working on AI

    OK so you think that might work? I have another quick question then... I am going to try and get this working on a DS using PA_lib since its dead easy to mess around with sprites and I want to implement some touch screenyness. However since the DS is... well.... rubbish with floats, is there an easy way to calculate the modulus without using floats or some crazy algorithm?
  5. So I'm working on some really simple AI for a side scrolling shooter. Basically I want the enemies to do a kamikaze style run at the player, I'm a bit of a newb with game development though so I'm having some trouble. Rooting through my old maths book I'm guessing the best way to do it would be to work out a unit vector in the direction of the player and then multiply this by the speed of the unit. To calculate the unit vector I need to: 1. Calculate the vector between the two points 2. Work out the modulus of that vector 3. Find the unit vector by: vector / modulus Am I on the right track here or is there something stupidly simple I've missed?
  6. Quote:Original post by ViLiO In your moveForward function you do position.x = position.x + hTheta; position.y = position.y - vTheta; ...why? You have a perfectly good look vector, you should use it [smile] Try changing that to... position.x += look.x; position.y += look.y; Regards, ViLiO Oh my god that was so simple, thank you sir! You are my new bestest freind! :D
  7. Ok thanks, rotation seems to be alright now (on its own at least) the problem I'm having is moving after the rotations, instead of going the direction the screen is facing it seems to be going in a completely different direction.
  8. Alright so I am trying to create a user input class for my amazing pryamid collection game, the problem is -well- the camera is all screwy, if i turn in some angles it goes forward like it should, at other angles it just goes backwards? This is the code that i have so far, bear in mine that my level is incorrectly aligned so -z = up, +y = look and -x = right; Here is what i do to create the camera. [source lang = "cpp"] void CCamera::setupCamera(LPDIRECT3DDEVICE9 gD3dDevice) { mD3dDevice = gD3dDevice; D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 5000.0f ); gD3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ); D3DXMatrixIdentity(&matView); matView._11 = right.x; matView._12 = up.x; matView._13 = look.x; matView._21 = right.y; matView._22 = up.y; matView._23 = look.y; matView._31 = right.z; matView._32 = up.z; matView._33 = look.z; matView._41 = D3DXVec3Dot( &position, &right ); matView._42 = D3DXVec3Dot( &position, &up ); matView._43 = D3DXVec3Dot( &position, &look ); 1.0f; gD3dDevice->SetTransform(D3DTS_VIEW,&matView ); // World Matrix // Just using identity (so triangle is at origin of world) D3DXMatrixIdentity(&matWorld); gD3dDevice->SetTransform(D3DTS_WORLD, &matWorld ); } So once its created I have rotate functions that look like this: [source lang = "cpp] void CCamera::panLeft (void) { D3DXMATRIX yawMatrix; D3DXMatrixRotationAxis (&yawMatrix, &up, DEGTORAD(TURN_SPEED_LEFT)); D3DXVec3TransformCoord (&look, &look, &yawMatrix); D3DXVec3TransformCoord (&right, &right, &yawMatrix); setupCamera (mD3dDevice); angle++; char buf[2048]; sprintf(buf,"eyeZ is %f \n", angle); OutputDebugString(buf); } void CCamera::panRight(void) { D3DXMATRIX yawMatrix; D3DXMatrixRotationAxis (&yawMatrix, &up, DEGTORAD(TURN_SPEED_RIGHT)); D3DXVec3TransformCoord (&look, &look, &yawMatrix); D3DXVec3TransformCoord (&right, &right, &yawMatrix); setupCamera (mD3dDevice); angle--; char buf[2048]; sprintf(buf,"eyeZ is %f \n", angle); OutputDebugString(buf); } and finally the function that is causing all the trouble: void CCamera::moveForward (void) { hTheta = 1*sin(angle); vTheta = 1*cos(angle); if (hTheta < 0) {hTheta = fabs (hTheta);} if (vTheta < 0) {vTheta = fabs (vTheta);} D3DXMatrixRotationX( &matWorld, vTheta ); position.x = position.x + hTheta; position.y = position.y - vTheta; setupCamera (mD3dDevice); char buf[2048]; sprintf(buf,"angle %f | hTheta %f | vTheta %f \n X %f | Z %f \n", angle, hTheta, vTheta, position.x, position.z); OutputDebugString(buf); } If someone could help me work this out I would be very VERY thankful, I'm totally stuck and have being for about 4 hours now. :( :( If you need any more source code its online here applogies for cross-posting, this is assignment work and I really need some help pretty soon-ish (it has to be in tomorrow :o
  9. Alright so I am trying to create a user input class for my amazing pryamid collection game, the problem is -well- the camera is all screwy, if i turn in some angles it goes forward like it should, at other angles it just goes backwards? This is the code that i have so far, bear in mine that my level is incorrectly aligned so -z = up, +y = look and -x = right; Here is what i do to create the camera. [source lang = "cpp"] void CCamera::setupCamera(LPDIRECT3DDEVICE9 gD3dDevice) { mD3dDevice = gD3dDevice; D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 5000.0f ); gD3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ); D3DXMatrixIdentity(&matView); matView._11 = right.x; matView._12 = up.x; matView._13 = look.x; matView._21 = right.y; matView._22 = up.y; matView._23 = look.y; matView._31 = right.z; matView._32 = up.z; matView._33 = look.z; matView._41 = D3DXVec3Dot( &position, &right ); matView._42 = D3DXVec3Dot( &position, &up ); matView._43 = D3DXVec3Dot( &position, &look ); 1.0f; gD3dDevice->SetTransform(D3DTS_VIEW,&matView ); // World Matrix // Just using identity (so triangle is at origin of world) D3DXMatrixIdentity(&matWorld); gD3dDevice->SetTransform(D3DTS_WORLD, &matWorld ); } So once its created I have rotate functions that look like this: [source lang = "cpp] void CCamera::panLeft (void) { D3DXMATRIX yawMatrix; D3DXMatrixRotationAxis (&yawMatrix, &up, DEGTORAD(TURN_SPEED_LEFT)); D3DXVec3TransformCoord (&look, &look, &yawMatrix); D3DXVec3TransformCoord (&right, &right, &yawMatrix); setupCamera (mD3dDevice); angle++; char buf[2048]; sprintf(buf,"eyeZ is %f \n", angle); OutputDebugString(buf); } void CCamera::panRight(void) { D3DXMATRIX yawMatrix; D3DXMatrixRotationAxis (&yawMatrix, &up, DEGTORAD(TURN_SPEED_RIGHT)); D3DXVec3TransformCoord (&look, &look, &yawMatrix); D3DXVec3TransformCoord (&right, &right, &yawMatrix); setupCamera (mD3dDevice); angle--; char buf[2048]; sprintf(buf,"eyeZ is %f \n", angle); OutputDebugString(buf); } and finally the function that is causing all the trouble: void CCamera::moveForward (void) { hTheta = 1*sin(angle); vTheta = 1*cos(angle); if (hTheta < 0) {hTheta = fabs (hTheta);} if (vTheta < 0) {vTheta = fabs (vTheta);} D3DXMatrixRotationX( &matWorld, vTheta ); position.x = position.x + hTheta; position.y = position.y - vTheta; setupCamera (mD3dDevice); char buf[2048]; sprintf(buf,"angle %f | hTheta %f | vTheta %f \n X %f | Z %f \n", angle, hTheta, vTheta, position.x, position.z); OutputDebugString(buf); } If someone could help me work this out I would be very VERY thankful, I'm totally stuck and have being for about 4 hours now. :( :( If you need any more source code its online here
  10. -pete-

    Problems loading .x file

    Hi Jeff, Thanks for your reply, I've done the changes you said and the model is now loading, thanks for that! I thought it wasn't displaying properly at first but if you change the -2000f to +2000f I can see the blue floor, just a couple more questions though, as I am thinking right now the model is standing vertically facing the camera, I was supposed to put it down into a first person view inside the maze (kind of like a mouse in a maze if you will) is there any way that i can rotate the model so that it is flat? Also is the scale right? Is the level going to be too small for my camera to move through? Thanks again Pete [Edited by - -pete- on August 24, 2006 2:42:06 PM]
  11. Hey all, I was wondering if you could help me with this, I am trying to load an .x file as a terrain, however whenever i try to load it i receive an "unhandled exception" error, I've based the code from directtutorial.com so it looks like it should work to me. The .x file is here if anyone wants to try loading it in their own program to see if its valid (I've tested it in the SDK viewer and it looks ok to me) anyway the model doesn't have any textures and it should look like this when its loaded... so thats what its supposed to look like, the code to load my file looks like: [source lang = "cpp"] void CRendering::LoadFromXFile(LPDIRECT3DDEVICE9 gD3dDevice) { HRESULT hr=D3DXLoadMeshFromX ("maze.X", D3DXMESH_SYSTEMMEM, gD3dDevice, NULL, &materialBuffer, NULL, &numMaterials, &maze); D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)materialBuffer->GetBufferPointer(); D3DMATERIAL9 *meshMaterials = new D3DMATERIAL9[numMaterials]; for (DWORD i=0; i<numMaterials; i++) { // Copy the material meshMaterials = d3dxMaterials.MatD3D; // Set the ambient color for the material (D3DX does not do this) meshMaterials.Ambient = meshMaterials.Diffuse; } materialBuffer->Release (); } Thats it to load, I know its pretty much ripped from the tutorial but i have to hack this together very quickly. Anyway once its loaded this is the source to render it: [source lang= "cpp"] void CRendering::RenderXFile(LPDIRECT3DDEVICE9 gD3dDevice) { for (DWORD i=0; i<numMaterials; i++) { // Set the material and texture for this subset gD3dDevice->SetMaterial(&meshMaterials); // Draw the mesh subset maze->DrawSubset( i ); } } And thats it... Am i missing something? If you want to look at the rest of the source, the most recent build is here feel try to test it.
  12. -pete-

    4D? huh?

    So I'm trying to work out some normals on pryamids that i am creating as collectables for my game. When reading on how to normalise vectors using D3DX I found this page on msdn what exactly is the w-component? Some kind of magnitude or something?
  13. -pete-

    What do i need?

    The first steps are simple... grow up and learn some manners, why should people help you if you are such an ass about it?
  14. -pete-

    Books - What do you recommend?

    I've got a trusty deitel and deitel "C++: How to program" on my desk, its pretty big and there is loads of stuff which isn't really necessary but its a good book to get you started on c++
  15. So i don't know who followed my old post but since i wasn't able to get anything working in the slightest i figured it might be worth a change in approach. I've decided to stick to the basics and just try to split some pre-written code up into individual classes so that i will be able to mess around with the data at a later date. The idea is simply to draw a triangle like the one shown below. Now I have a triangle class that is supposed to have two functions, the first is to create the triangle and the second is to render it. I've tried creating the triangle in the main function and rendering it using the code in the triangle class and that works fine. However when i try to create the triangle in the triangle class I get a black screen empty screen with the line First-chance exception at 0x7c812a5b in GS2Test.exe: Microsoft C++ exception: long at memory location 0x0012fbcc.. appearing in the debug plane every frame. Hence, I know that the problem lies in the creation of the creation of the triangle rather than any problems with rendering it. Here is the code: bool CTriangle::createTriangle(LPDIRECT3DDEVICE9 gD3dDevice, LPDIRECT3DVERTEXBUFFER9 gVertexBuffer) { HRESULT hr=gD3dDevice->CreateVertexBuffer(3*sizeof(CVertex),D3DUSAGE_WRITEONLY, MYVERTEX_FVF, D3DPOOL_MANAGED, &gVertexBuffer, NULL ); if (FAILED(hr)) return false; // Lock and fill CVertex* pVertices=NULL; hr=gVertexBuffer->Lock(0,0,(void**)&pVertices,0); if (FAILED(hr)) return false; // Fill in position and colour values for our 3 vertices // It is essential that the vertices are defined in clockwise order pVertices[0].p=D3DXVECTOR3(-1.0f,0.0f,0.0f); pVertices[0].c=D3DCOLOR_XRGB(255,0,0); // Red pVertices[1].p=D3DXVECTOR3(-1.0f,1.0f,0.0f); pVertices[1].c=D3DCOLOR_XRGB(0,255,0); // Green pVertices[2].p=D3DXVECTOR3(+1.0f,0.0f,0.0f); pVertices[2].c=D3DCOLOR_XRGB(0,0,255); // Blue gVertexBuffer->Unlock(); return true; } Now this code is exactly the same in the main.cpp and triangle.cpp files with the exception that i don't pass the gD3dDevice and gVertexBuffer in (since they're global)... so... is there any reason why this code works in one place and not the other? And whats with the error messages? if you want the code for the rendering function it is: void CTriangle::renderTriangle(LPDIRECT3DDEVICE9 gD3dDevice, LPDIRECT3DVERTEXBUFFER9 gVertexBuffer) { // To draw we pass the vertices down a stream. We set the source as our vertex buffer gD3dDevice->SetStreamSource(0,gVertexBuffer,0,sizeof(CVertex)); // We then tell Direct3D the make up of the vertices gD3dDevice->SetFVF(MYVERTEX_FVF); // Now draw our one triangle gD3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,1); }
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!