Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Everything posted by Steve-B

  1. Steve-B

    Camera Rotation using gluLookAt

    Ok, I've managed to get it working now. Tried to delete this thread but looks like I left it too long. Moderators?
  2. Hi. I am setting up a camera using gluLookAt and I'm not sure how to do rotations. I have the first camera lesson from the Game Tutorials site so I can make the camera move forwards and backwards but how do you make it rotate? I've been told lesson 2 and 3 show how to achieve this. Would anyone be willing to e-mail me those tutorials or give some advice on what do to. Thanks.
  3. Hi guys & gals I know this isn't strictly an OpenGL issue but it's still games related. Basically I'm having trouble adding a custom mouse pointer to my OpenGL game. I don't want the standard windows mouse pointer as it just looks naff in a game. Plus I want the cursor to change when the mouse is positioned over certain objects in the game. I'll figure that part out myself though. Anyway I have created the cursor in Visual Studio 6 in the same way I created an icon for the program. I used the usual resource file creation method that worked for my program icon. Unfortunately when the program loads the mouse pointer just shows up as the hourglass cursor. I'm loading the cursor as a resource and I can't figure out why this doesn't work. Is there anything special you have to do for cursors? Do they have to be a certain size or number of colours? Are there any tutorials on the net?? Cheers, Steve
  4. I'm playing about with lighting through Cg. I have setup a basic lighting algorithm which calculates diffuse,specular, global ambient etc. I also have some nice looking distance attenuation going on. It is using the same basic model as OpenGL. I am lighting all my objects in their local object-space and it's been working great... until they move. Then I found that the lighting still think they're in their original location and they end being completely unlit. Not a good thing. How can I solve this?? Is this a limit with lighting in object space? Do I need to perform my lighting in eye-space instead?? Sre there any tutorials on lighting in eye space?? How do you do this because I am unable to get the same visual effect like I had in my object-space calculations. The lighting keeps flying off everytime I rotate the camera and it only lights the scenery properly when I'm looking directly down the negative Z axis. Looking down the positive Z axis causes the scene to go pitch black. This may be linked to the light flying off when the camera is rotated. Anyone got any advice?? :) Cheers, Steve
  5. Here is the code that I'm using. Mhamlin: If you look at the code you will see the lines which perform the modelview inverse calculations. They are commented out cos of the problems I've been having. I think I may have to send the camera view vector to the cg function as well as the eye position. Maybe?? Output VertexShader(Input IN, Lighting LIGHT, Surfaces MATERIAL, uniform float4 eyePosition, uniform float3x3 modelView, uniform float4x4 modelViewInverse, uniform float3x3 modelViewInvTrans, uniform float4x4 modelViewProj) { Output OUT; // Here we convert the output vertex from object-space to clip-space OUT.position = mul(modelViewProj, IN.position); // Set the material ambient property to 100% by default (temporary??) MATERIAL.Ka = (1.0, 1.0, 1.0); // *** NEW EYE-SPACE TRANSFORMATIONS *** float3 P = IN.position.xyz; float3 N = IN.normal.xyz; // Convert the vertex position from object-space to eye-space /* float3 P = mul(modelView, IN.position.xyz); normalize(P); // Convert the vertex normal using the inverse transpose of the modelview matrix float3 N = mul(modelViewInvTrans, IN.normal); normalize(N); */ // Multiply the light position by the inverse modelview matrix // float3 L = mul(modelViewInverse, LIGHT.position - P); float3 L = normalize(LIGHT.position.xyz - P); // *** NEW EYE-SPACE TRANSFORMATIONS *** // Calculate the attenuation float attenuation = Attenuation(P, LIGHT); // Compute the emmisive term float3 emmisive = MATERIAL.Ke; // Compute the ambient term float3 ambient = MATERIAL.Ka * LIGHT.ambient.xyz; // Compute the diffuse term float diffuseLight = max(dot(N, L), 0); float3 diffuse = MATERIAL.Kd * LIGHT.colour.xyz * diffuseLight * attenuation; // Compute the specular term float3 V = eyePosition.xyz; float3 H = normalize(L + V); float specularLight = pow(max(dot(N, H), 0), MATERIAL.shininess); if(diffuseLight <= 0) specularLight = 0; float3 specular = MATERIAL.Ks * LIGHT.colour.xyz * specularLight * attenuation; // Compute the final vertex colour float3 lighting = (emmisive + ambient + diffuse + specular); // Pass the texture in Texture Unit 0 to the fragment program OUT.texCoord = IN.texCoord; // Pass the current colour to the fragment program OUT.colour.xyz = IN.colour.xyz * lighting; OUT.colour.w = IN.colour.w; return OUT; }
  6. Steve-B

    How on earth do you load a custom cursor??

    Thanks for the help. Looks like I'll have to take the OpenGL route as I still can't get the pointer working through the Windows functions. Not sure what I'm doing wrong. I've taken the advice 'lack' but still it doesn't work. I'll use the OpenGL method. Cheers.
  7. Hi I'm playing with lighting at the moment and I ahve written my lighting code as part of a Cg script file. It works great but now I've added distance attenuation and I'm not getting the results I'm looking for. What I want to know is how do the following constants affect the final image? GL_CONSTANT_ATTENUATION GL_LINEAR_ATTENUATION GL_QUADRATIC_ATTENUATION What I'm trying to achieve is a similar effect to fogging. I want polygons at a certain distance to be completely blacked out. At the moment it looks pretty good but I want the distance the light extends to be much shorter. Anyone got any advice on this subject?? STeve
  8. Steve-B

    How on earth do you load a custom cursor??

    I'm already using the LoadCursor function. I'm using it in the same way that I use the LoadIcon function. I use it like this: winclass.hIcon = LoadIcon(NULL, "IDI_WATERDEEP"); winclass.hCursor = LoadCursor(NULL, "IDC_WATERDEEP"); Using this code the icon works great but the cursor just shows up as the standard windows hour glass cursor.
  9. Hi I think this is a basic question but here goes. I'm trying to move a simple object around the screen but I want it to move according to it's own axis. The object is a little car object and I want it to be able to turn and then translate in the direction it's facing. I believe I need to use vectors for this so I have written my own vector class but I'm not really sure how to use it to achieve the effect I'm looking for. Do I have to use the objects local coordinate system or something? Steve
  10. Steve-B

    How to control an object in 3D space

    Ok, I guess I'll post some code: The problem I have is when i translate (from the origin) along an axis and then try to rotate around the objects centre of gravity. Instead the object rotates in a big circle around the centre of the world coordinate system. I remember having a similar problem ages ago but I can't remember how I fixed it. This is my main render function: // This is the main drawing function which is called every frame... void Render(CLOCK *time) { // First we need to clear the screen and the depth buffer... glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Reset the Modelview Matrix (start with a nice clean slate) glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /****** STAGE 1: CALCULATE THE VIEWING TRANSFORMATION! ******/ glTranslatef(0.0f, 0.0f, -15.0f); /****** STAGE 2: CALCULATE THE MODELLING TRANSFORMATION! ******/ Draw3D(); Draw2D(time); /****** STAGE 3: FLUSH THE OPENGL GRAPHICS PIPELINE ******/ glFlush(); } This is the Draw3D() function: void Draw3D(void) { glDisable(GL_CULL_FACE); glPushMatrix(); QuatRotation(); // Perform object rotation // We need to find the direction vector from the object position to it's facing directon // To do this we take the end point (N) and subtract the starting point (C). //CVector N = camera_quat.GetAxis(); //CVector Delta = (N - position); // Calculate our new direction vector //position += (Delta * 0.01f); // Increase the camera position in the direction we're facing // N += (Delta * speed); // Increase the view position in the direction we're facing // First we translate into position... glTranslatef(position.x, position.y, position.z); // Here we pass the 'modelview projection matrix' to our Cg program cgGLSetStateMatrixParameter(modelViewProj, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); // Next we enable our Cg vertex profile and bind the vertex program cgGLEnableProfile(shader->vertexProfile); cgGLBindProgram(basicProgram); // Next we enable our Cg fragment profile and bind the fragment program cgGLEnableProfile(shader->fragmentProfile); cgGLBindProgram(fragmentProgram); // Finally we display the light object glBegin(GL_QUADS); /*glColor3f(1.0f, 1.0f, 1.0f); glVertex3f(0.0f, 0.0f, -1.0f); // LEFT glVertex3f(-0.5f, 1.0f, 1.0f); glVertex3f(-0.5f, -1.0f, 1.0f); glColor3f(1.0f, 1.0f, 1.0f); glVertex3f(0.0f, 0.0f, -1.0f); // RIGHT //glColor3f(red, green, blue); glVertex3f(0.5f, -1.0f, 1.0f); glVertex3f(0.5f, 1.0f, 1.0f);*/ glColor3f(red, green, blue); glVertex3f(0.5f, 0.8f, -1.0f); glVertex3f(-0.5f, 0.8f, -1.0f); // TOP glVertex3f(-0.5f, -0.8f, -1.0f); glVertex3f(0.5f, -0.8f, -1.0f); /*glColor3f(1.0f, 1.0f, 1.0f); glVertex3f(0.0f, 0.0f, -1.0f); // BOTTOM //glColor3f(red, green, blue); glVertex3f(0.5f, -1.0f, 1.0f); glVertex3f(-0.5f, -1.0f, 1.0f);*/ glEnd(); // Disable the vertex/fragment profiles so we can render the point light using ordinary T&L cgGLDisableProfile(shader->fragmentProfile); cgGLDisableProfile(shader->vertexProfile); glPopMatrix(); glEnable(GL_CULL_FACE); }
  11. This is what my main loop looks like. It constantly reads the input devices every frame and saves the information in the structures/array. It all seems fine to me but I'm sure something must be wrong somewhere. If not then I guess the crash must be down to a bad graphics driver. Note that the devices do actually work and I can successfully read data from the input devices. Also I have put these three stuctures/array as externs in my Main.h header file so they are accessible to other files within my program. This couldn't be the cause of the problem could it? Anyway here is the code for my program main loop: Hope someone can help, Steve-B UCHAR key_state[256]; // Create our array for storing the keyboard state DIMOUSESTATE2 mouse_state; // Create a pointer to the mouse state structure DIJOYSTATE2 joy_state; // Create a pointer to the joystick state structure // THE MAIN WINDOWS EVENT LOOP while(TRUE) { if(!r3d->ProcessMessages()) // Quit if the function returns FALSE break; dinput->UpdateKeyboard(key_state); // Check the keyboard for key presses dinput->UpdateMouse(&mouse_state); // Check the mouse for clicks/movements dinput->UpdateJoystick(&joy_state); // Check the joystick for any actions Update(timer->elapsed); // Update the display Render(timer->clock); // Render the display SwapBuffers(r3d->hDC); // Swap the buffers (Double Buffering) timer->UpdateTimer(); // Update the current timer (measured in seconds) timer->UpdateFrame(); // Update the frame rate (measured in frames per second) }
  12. Hi guys Ever since I added DirectInput code to my program (about a year ago) every now and again my program crashes, seemingly randomly. The error I recieved was the standard XP 'Please tell Microsoft about this problem' message. If I click on debug I am given a memory location and that a 'memory write error occured'. The crash can occur after a minute or two and I have successfully ran my program for hours before it crashes with the same problem. I'd like to know if there is something you guys can see that I'm doing wrong in my DirectInput code. I've done some testing and it doesn't appear to crash when I remove the DirectInput function calls. I think I might have tracked the bug down to the UpdateKeyboard function but I'm not 100% on this. UpdateMouse and UpdateJoystick seem to be fairly stable. Here is my the code in DirectInput.cpp: // Call this function in WinMain to update the keyboard state in real-time bool DirectInput::UpdateKeyboard(LPVOID keyboard_state) { hr = lpdiKeyboard->GetDeviceState(sizeof(UCHAR[256]), keyboard_state); if(FAILED(hr)) { if(hr == DIERR_INPUTLOST) { // The device has been lost so we attempt to reacquire it... hr = lpdiKeyboard->Acquire(); if(FAILED(hr)) return FALSE; } } return TRUE; } // Call this function in WinMain to update the mouse state in real-time bool DirectInput::UpdateMouse(DIMOUSESTATE2 *mouse_state) { hr = lpdiMouse->GetDeviceState(sizeof(DIMOUSESTATE2), mouse_state); if(FAILED(hr)) { if(hr == DIERR_INPUTLOST) { // The device has been lost so we attempt to reacquire it... hr = lpdiMouse->Acquire(); if(FAILED(hr)) return FALSE; } } return TRUE; } // Call this function in WinMain to update the joystick state in real-time bool DirectInput::UpdateJoystick(DIJOYSTATE2 *joystick_state) { if(joystick_found) { hr = lpdiJoystick->Poll(); // Poll is only required for joysticks! if(FAILED(hr)) { if(hr == DIERR_INPUTLOST) { // The device has been lost so we attempt to reacquire it... hr = lpdiJoystick->Acquire(); if(FAILED(hr)) return FALSE; } } hr = lpdiJoystick->GetDeviceState(sizeof(DIJOYSTATE2), joystick_state); if(FAILED(hr)) return FALSE; } return TRUE; }
  13. Hi My lightwave object loader is almost finished apart from one little problem. I can't find any texture mapping coordinates in the model files. I'm using Lightwave 5 and the objects it produces don't seem to contain any texture coordinates. So how on earth am I supposed to texture an object with no coordinates??? Do I have to calculate them myself??? Anyone got any experience of writing a Lightwave object loader and come across this problem? Steve
  14. Hi All This is a bit of an advanced question about display lists. I was contemplating whether to post this on the opengl.org advanced forum or here. I couldn't be arsed to setup an account on OpenGL.org so here we are. lol. Anyway the problem is that I have created a class that loads a Lightwave model. The model polygon and vertex data is stored in pointers within the class. Now I then load the model into my opengl app by created a pointer to the class: Lightwave *model = NULL; Then I initialise the model as normal and load the object into the memory. Now here is where display lists come in. The data is then passed to a display list using the array version of the opengl commands. I then delete the model data freeing up the memory it used and the model is display using the display list and it works fine. The problem is my program sometimes crashes and it is very annoying. The only time it doesn't crash is when I remove the display list code. The error message I recieve is always an unreferenced memory error. Is there something I should know about display lists that is going on behind the scenes?? Steve
  15. Steve-B

    Display Lists (advanced question)

    Hi Thanks for your replies. I might give the glDrawElements a bit of investigation and see what happens when I use that. I'll just say that my program would not instantly crash. It would run for between 30 minutes to sometimes 3 or more hours before crashing with a memory error message. Well my code is now pretty stable (but that's without display lists). It also seems to be more stable since I changed all the objects in my demo to use pointers... For example I have a vector class which I used to create an object with. Vector camera; Set the code running and went off to work. By the time I got home (9 hours later) it had crashed. So I changed that new addition to my program to this: Vector *camera; Initialise the camera (allocate RAM for it) in my setup function and the program didn't crash and ran for over 9 hours. Maybe I'm barking up the wrong tree but this sort of thing affects my engine. I'm not sure why though. I didn't think there was anything wrong with using the first method. Which method does everyone else use for adding objects to your demos?? Steve-B
  16. Hi Hi everyone I have an odd problem which has left me completely stumped. I am loading in a file format which has the byte ordering in the Big-Endian format. When I read in data from the file I have to reverse the bytes to the win32's Little-Endian format. Now this isn't too much of a problem as I've set up a few methods within my program class which reads in data from the file (be it unsigned long, int, unsigned int) and then copies the data (using shifting) into a 4-byte bit-field structure. Reversing the bytes and updating the variables real value is then the simple matter of a macro which shifts the bytes to their correct positions. This method works perfect for int's unsigned long's etc BUT not for float's. C does not allow shifting within floating point variables and floats can't be stored within a bit-field structure. I tried reading the data into an unsigned long splitting up the byte and then copying the resultant value to a floating point variable but of course the number was completely wrong. I then found out this is because of the IEEE format. Seems a bit like a vicious circle to me?? Is there any way out? I did find a horrible hack solution where I read the float data into an unsigned long, reversed the bytes and then wrote the data back out to a temporary file and then read the data from this file into a floating point variable to retrieve the proper value. This works but of course, it's not exactly ideal. I'm really stuck for a decent solution to this problem. Anyone had any experience of this problem?? Steve
  17. UPDATE: Ok, I gave the reinterpret_cast code a try out and... it didn't work. I used pretty much the exact same code that Andrew provided. The error I recieved was that I can't do a reinterpret_cast when a standard cast will perform the same function. That was the basic gist of the error message. It didn't really make a lot of sense to me though so I just gave in with it. I decided to try and look for another solution and luckily I found it. I couldn't believe I hadn't thought of it before now and I can't believe no-one else thought of this. It was sooo simple when I thought about it. It was a kind of eureka moment. lol. All I had to do was create a new ReverseBigEndian function that returns a float. I pass the floating point data to the function as a longword and reverse the bytes as normal. Then I just use a memcpy to copy the exact bit-structure of the data to a floating point variable. Hey presto, I get the proper value! :) float LWOB::ReverseBigEndian(unsigned long iffData) { LONGWORD_STORAGE lws; float temp = 0.0f; lws.byte1 = iffData; lws.byte2 = iffData >> 8; lws.byte3 = iffData >> 16; lws.byte4 = iffData >> 24; iffData = REVERSE_BIG_ENDIAN_LW(lws.byte1, lws.byte2, lws.byte3, lws.byte4); memcpy(&temp, &iffData, sizeof(unsigned long)); return temp; } It works great! :D
  18. Quote:Original post by iMalc Nope, unfortunately that guess is wrong. Andrew's code has it sorted. Yes, that presumption is quite wrong. The bytes are indeed reversed in floating point data. Anyway, thanks very much for everyone's contributions. I'm going to have a good think about everyone's comments and have a play with Andrew's code which look like it will solve my little problem. I'd never even heard of reinterpret_cast before! Looks like you do learn something everday. lol. :) Cheers, Steve
  19. Steve-B

    OpenGL program crashes every so often...

    Hi guys Thanks for the replies. I do know how to debug! lol. I've ran it thtough the debugger but it only stops on an instruction in assembler language. I am still confused by the problem though. I've tried taking everything out of the main loop and having just the bare minimum of outputting different coloured cube objects on the screen. Not even any texturing (I took that out). The program does not change any pointers or anything during the life of the program. It starts running and does the same thing over and over. After taking out the texturing it seemed to run a bit longer 1 hour 20 mins before crashing with the same error. Sometimes it takes the entire computer down with it. I am getting so annoyed with this now. I know it's not an OpenGL problem but what could it be. I even formatted an reinstalled windows xp to get rid of the annoying virus I had in the hope that that would cure the problem. Is there a small possibility that there could be a fault with my hardware. Like my RAM for example?? Thanks for your all your input. :) Steve
  20. Hi I thought the problem maybe related to my lack of ram however the problem only occurs in my opengl application. I only have 192MB of RAM and my c drive is about 95% full so this may be the cause. Strange how I only recieve the error when I run my program though. Other opengl programs I've downloaded don't crash during program execution. The time of the program crash also seems to occur randomly and without warning. Here is the error message: The instruction at "0x6962e3b0" referenced memory at "0x00000000". The memory could not be "written". Any ideas?? Steve
  21. Steve-B

    OpenGL program crashes every so often...

    Hi Thanks for the replies. I am using C++ but I'm not really too sure what you mean Enigma. I'll take a close look at my pointers and see if I can fix anything. I'll also look into setting up VC++ to break at the problem line of code. Steve
  22. Hi peeps I'm learning Cg at the moment and it's going fairly well. However I like to understand the underlying mechanics also. I've been going through some source code on my computer and I'm trying to convert the assembly code to Cg code. The program is a very simple one so does anyone know what the Cg equivalent would be?? I've tried to understand the code by heavily commenting it. I think I'm on the right lines although the lighting code has got me a little confused. The object being rendered is a GLUT torus with it's own internal normals and the light is simply pointing in the positive z-axis (0,0,1). Here is the source I'm trying to convert: // These four instructions convert the vertices from object space -> eye space DP4 R0.x,v[OPOS],c[0]; // ModelView transformation (Store the results in register R0) DP4 R0.y,v[OPOS],c[1]; // Register v[OPOS] contains the object-space vertex coordinates DP4 R0.z,v[OPOS],c[2]; // Registers c[0] to c[3] contain the modelview matrix DP4 R0.w,v[OPOS],c[3]; // Calculation = (object space coordinates * modelview matrix) // These four instructions convert the vertices from eye space -> clip space DP4 R1.x,R0,c[4]; // Projection transformation (Store the results in register R1) DP4 R1.y,R0,c[5]; // Register R0 contains the eye-space vertex coordinates DP4 R1.z,R0,c[6]; // Registers c[4] to c[7] contain the projection matrix DP4 R1.w,R0,c[7]; // Calculation = (eye space coordinates * projection matrix) // These four instructions convert the vertex normals from object space -> eye space??? Is this right?? DP3 R2.x, c[0], v[NRML]; // Normal transformation (Store the results in register R2) DP3 R2.y, c[1], v[NRML]; // Register v[NRML] contains the vertex normal coordinates) DP3 R2.z, c[2], v[NRML]; // Calculation = modelview matrix * vertex normal) DP3 R2.w, c[8], R2; // Lighting calculation (Register c[8] contains the light direction) Not sure About this one! // This instruction multiplies the current vertex colour with the new lighting colour // This new vertex colour is then stored in register R3 ready to be output to the GPU MUL R3.xyzw,v[COL0].xyzw,R2.wwww; MOV o[COL0],R3; // Copy register R3 to the COL0 output register (vertex colour) MOV o[HPOS],R1; // Copy register R1 to the HPOS output register (clip-space position)
  23. Hi Has anyone had much experience using Cg and OpenGL? I've started having a play around with it and I've got quite far. I'm learning from the official Cg tutorial book and have reached the chapter on lighting. By the way I thoroughly recommend this book to any OpenGL programmers as it's excellent. Anyway my problem is that I've created a simple phong-style lighting model (straight from the book - chapter 5) and I've managed to get a nice object of a space ship textured and lit through Cg. The lighting takes place in the vertex program and my fragment program basically just deals with the position of the texture. I can move the light object around and it looks pretty good. The problem is that I can move the light object however the light itself is locked in relation to the object. For example when the light is behind the ship and the ship rotates around it's axis the lighting remains the same. As though the light is moving with the ship model. I somehow need to tell the vertex program the new light position. It doesn't seem to mention this in the book. Anyone got any ideas?? Cheers, Steve
  24. Hi I've managed to convert most of my program from using the c FILE to using proper Windows handles. I've converted my fread to ReadFile and so on. Now part of my program requires the use of ftell() so my program knows where it is in the file. What is the Windows equivalent of this function? I've not been able to find it. The other command equivalent I'm looking for is the fseek command so I can skip past parts of a file that I'm not interested in. Any ideas?? Cheers, Steve
  25. Quote:Original post by Kiput Slight off topic, but don't convert standard ansi C IO to Windows crap. If you'd had look at Windows CRT sources you would see that these functions (fopen, fread, etc.) use core win ones (ReadFile, etc.). Basically, fread calls ReadFile to perform IO. Kiput, I think you mean ReadFile calls the fread function, no?? ReadFile is not a core function. Thanks for the replies. Look, I would love to stick with the standard i/o functions but I've found no way of discovering a file's date/time stamp using these functions. Maybe I've just not looked hard enough. The only function I found which allows you to do this requires windows file handles, hence the switch to file handles. The other is an old dos function. If someone know of a better way to find the date/time stamp using standard i/o functions I'd love to hear it. :) Steve
  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!