Sign in to follow this  
Ruudje

OpenGL Engine crashing due to camera angle?

Recommended Posts

Ruudje    100
Hi all, I'm facing a strange problem I have been unable to figure out by myself... I have restarted a basic opengl engine, with support for 3ds files and bmp textures so far. On to the problem: I added some simple formulas to make the camera perform a certain fly-by of the default model. I used the sin and cos functions with timeGetTime, nothing special, but after a certain time (I THINK it's because of the angle of the camera) the screen freezes and goes black after which the system crashes. If it doesn't crash, the system resets the VPU (ATI Radeon 9700 Pro) so the screen goes black for 1 second, resumes the program only to still crash within the next minute. I have tried 2 completely different models, both with the same resutls. I have tried the program without the formulaes, i.e. a static camera, and then it works fine. What could be causing this?

Share this post


Link to post
Share on other sites
deavik    570
Check by outputting values after your sin / cos functions but before rendering where you are getting a divide-by-zero. I think it's a pretty safe bet that that is the problem here.

/edit: Darn, beaten! I opened this window and checked my e-mail before replying.

Share this post


Link to post
Share on other sites
Ruudje    100
Here's the function that renders the default model


void Update(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

if(myApp->GetKey(VK_ESCAPE))
{
myApp->Update_ptr = &Quit;
return;
}

gluLookAt( 400.0f,
300.0f,
600.0f,
0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f
);

GLfloat LightPosition[]= { 1.0f, 0.6f, 0.7f, 0.0f };
glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);

glBegin(GL_TRIANGLES);

obj_Default.Render_3ds();

glEnd();
}



This is the code that doesn't crash. If I alter the GLU_Lookat to...


gluLookAt( sin(timeGetTime() / 1500.0f) * 1200,
cos(timeGetTime() / 1400.0f) * 1200,
600.0f,
0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f
);



...things go wrong as described above.

Share this post


Link to post
Share on other sites
delta user    164
cast the timegettime() function to a float: (float)timegettime()
because it returns a short integer.(I think dword is a short integer)
and change 1200 into 1200.0f

this are the two things where it could go wrong.



veel geluk

[Edited by - delta user on December 3, 2005 7:07:11 AM]

Share this post


Link to post
Share on other sites
Seroja    280
Try to write your own code instead of gluLookAt. Then if there is division by 0 you'd get a runtime error, and maybe even a line number.

This is kinda weird, only tan usually causes problems, not sin and cos.

Share this post


Link to post
Share on other sites
delta user    164
I tried your code in one of my apps and it works fine.

It is verry weird because your app doesn't crash immediatly.

if it would be the camera code it should crash when your camera code gets executed for the first time and that would be when you start your app.

sorry for the code above. it was bad code so i removed it.

Share this post


Link to post
Share on other sites
darookie    1441
Things like resetting VPUs are mostly caused by buffer overruns or invalid indices - you better double-check your 3DS rendering code. I really can't imagine how any messed up camera matrix could cause such problems.
Are you by any change using VAs or VBOs? If so, take a close look at those. If not , check your 3DS loader for invalid indices.

HTH,
Pat

Share this post


Link to post
Share on other sites
LilBudyWizer    491
Try changing your up vector to (0,1,0). If that solves it then it is the angle you are using. Specifically you are hitting an angle where both sin and cos are returning zero. Not because the sin and cos of any given angle are both zero, but because you are so far out of the interval of convergence. You should use something like (((float)(timeGetTime() / A) % B) / B) * 2*PI to calculate the angle. The loop given above is wrong. It's wrong because it will most likely produce a huge negative angle and wrong numerically because you can't subtract your way back into range when you are so far out of range.

You should change how you calculate the angle regardless. What you're doing should be producing fairly irratic movement. If changing that up vector doesn't eliminate the crash then changing how you calculate the angle won't eliminate it either. Changing the up vector eliminates the possibility that you are generating (0,0,600) as the point you are looking at. The other major error you could make with LookAt is to look at the point the camera is at, but with the hardcoded 0 and 600 that isn't likely.

It is possible. How it can happen is addressing memory incorrectly. When you start stomping on memory all kinds of impossible things become possible. If you haven't commented out the call to render the scene then you might want to give it a try. It would make no sense that doing that would fix the problem so if it does then you most likely stomped on memory in that routine. If it stops the crash then obviously something in there was causing it.

Share this post


Link to post
Share on other sites
Ruudje    100
Changing the up-vector didnt help.

I'm using the 3ds-loader from www.morrowland.com. Used it before in a project and it worked fine then...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By markshaw001
      Hi i am new to this forum  i wanted to ask for help from all of you i want to generate real time terrain using a 32 bit heightmap i am good at c++ and have started learning Opengl as i am very interested in making landscapes in opengl i have looked around the internet for help about this topic but i am not getting the hang of the concepts and what they are doing can some here suggests me some good resources for making terrain engine please for example like tutorials,books etc so that i can understand the whole concept of terrain generation.
       
    • By KarimIO
      Hey guys. I'm trying to get my application to work on my Nvidia GTX 970 desktop. It currently works on my Intel HD 3000 laptop, but on the desktop, every bind textures specifically from framebuffers, I get half a second of lag. This is done 4 times as I have three RGBA textures and one depth 32F buffer. I tried to use debugging software for the first time - RenderDoc only shows SwapBuffers() and no OGL calls, while Nvidia Nsight crashes upon execution, so neither are helpful. Without binding it runs regularly. This does not happen with non-framebuffer binds.
      GLFramebuffer::GLFramebuffer(FramebufferCreateInfo createInfo) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); textures = new GLuint[createInfo.numColorTargets]; glGenTextures(createInfo.numColorTargets, textures); GLenum *DrawBuffers = new GLenum[createInfo.numColorTargets]; for (uint32_t i = 0; i < createInfo.numColorTargets; i++) { glBindTexture(GL_TEXTURE_2D, textures[i]); GLint internalFormat; GLenum format; TranslateFormats(createInfo.colorFormats[i], format, internalFormat); // returns GL_RGBA and GL_RGBA glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, createInfo.width, createInfo.height, 0, format, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); DrawBuffers[i] = GL_COLOR_ATTACHMENT0 + i; glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, textures[i], 0); } if (createInfo.depthFormat != FORMAT_DEPTH_NONE) { GLenum depthFormat; switch (createInfo.depthFormat) { case FORMAT_DEPTH_16: depthFormat = GL_DEPTH_COMPONENT16; break; case FORMAT_DEPTH_24: depthFormat = GL_DEPTH_COMPONENT24; break; case FORMAT_DEPTH_32: depthFormat = GL_DEPTH_COMPONENT32; break; case FORMAT_DEPTH_24_STENCIL_8: depthFormat = GL_DEPTH24_STENCIL8; break; case FORMAT_DEPTH_32_STENCIL_8: depthFormat = GL_DEPTH32F_STENCIL8; break; } glGenTextures(1, &depthrenderbuffer); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); glTexImage2D(GL_TEXTURE_2D, 0, depthFormat, createInfo.width, createInfo.height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthrenderbuffer, 0); } if (createInfo.numColorTargets > 0) glDrawBuffers(createInfo.numColorTargets, DrawBuffers); else glDrawBuffer(GL_NONE); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) std::cout << "Framebuffer Incomplete\n"; glBindFramebuffer(GL_FRAMEBUFFER, 0); width = createInfo.width; height = createInfo.height; } // ... // FBO Creation FramebufferCreateInfo gbufferCI; gbufferCI.colorFormats = gbufferCFs.data(); gbufferCI.depthFormat = FORMAT_DEPTH_32; gbufferCI.numColorTargets = gbufferCFs.size(); gbufferCI.width = engine.settings.resolutionX; gbufferCI.height = engine.settings.resolutionY; gbufferCI.renderPass = nullptr; gbuffer = graphicsWrapper->CreateFramebuffer(gbufferCI); // Bind glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); // Draw here... // Bind to textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textures[0]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textures[1]); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, textures[2]); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); Here is an extract of my code. I can't think of anything else to include. I've really been butting my head into a wall trying to think of a reason but I can think of none and all my research yields nothing. Thanks in advance!
    • By Adrianensis
      Hi everyone, I've shared my 2D Game Engine source code. It's the result of 4 years working on it (and I still continue improving features ) and I want to share with the community. You can see some videos on youtube and some demo gifs on my twitter account.
      This Engine has been developed as End-of-Degree Project and it is coded in Javascript, WebGL and GLSL. The engine is written from scratch.
      This is not a professional engine but it's for learning purposes, so anyone can review the code an learn basis about graphics, physics or game engine architecture. Source code on this GitHub repository.
      I'm available for a good conversation about Game Engine / Graphics Programming
    • By C0dR
      I would like to introduce the first version of my physically based camera rendering library, written in C++, called PhysiCam.
      Physicam is an open source OpenGL C++ library, which provides physically based camera rendering and parameters. It is based on OpenGL and designed to be used as either static library or dynamic library and can be integrated in existing applications.
       
      The following features are implemented:
      Physically based sensor and focal length calculation Autoexposure Manual exposure Lense distortion Bloom (influenced by ISO, Shutter Speed, Sensor type etc.) Bokeh (influenced by Aperture, Sensor type and focal length) Tonemapping  
      You can find the repository at https://github.com/0x2A/physicam
       
      I would be happy about feedback, suggestions or contributions.

    • By altay
      Hi folks,
      Imagine we have 8 different light sources in our scene and want dynamic shadow map for each of them. The question is how do we generate shadow maps? Do we render the scene for each to get the depth data? If so, how about performance? Do we deal with the performance issues just by applying general methods (e.g. frustum culling)?
      Thanks,
       
  • Popular Now