OpenGL I need help from all of you!

Recommended Posts

rayan14    100
Hello my name is Ryan im 14 years old from Turkey, cheers everyone I started ogl programming a few months ago and i am going good but i have a very serious bug that i am stuck in for 2 months! I have a very simple OpenGL project that is not working right. After looking for info on the Internet, it turns out that the glRotatef() function does the transform local to the object, and does not do a global transform. So the order of operation of is important. In the function Cylinder::ProcessMessage(), processing for the MSG_ROTATE_CURRENT_STATE message, there is an if to check if the rotation is ‘positive’ or ‘negative’ it is just dumb luck that doing the rotations in the backward order works for this program, but to add functionality, I need a function for global rotation. There has to be a function to do global rotation!!! Run the scope project, and press the ‘go’ button. The window has two cylinders, but one of them starts with a view straight-on, so you must use the arrow keys on the keyboard to see one of the cylinders. Can you please help me? I have uploaded source code of the project here: www.albayoung.com/kosta/OGL.zip Please help me!!!!! thank you very much for your time. I owe a very big favour to all who help me :)

Share on other sites
rayan14    100

please! this bug is driving me crazy

Share on other sites
skiritis    144
take a breath there kid.
relax,
before trying coding more, since you have all your life ahead of you ( 14 years old ?? ) take some time and study some basic matrix mathematics and then some basic opengl matrix / matrix stack stuff. I guess you are familiar with some opengl concepts but obviously you must master some more before you can say you are stuck because of a bug.
At this point you are, most probably, doing something in a way that you shouldn't.
Pace yourself, study more opengl, before going deep into complex stuff.

you can start from these tutorials here ( http://nehe.gamedev.net )
they are not the best code practices but they have helped a lot of people ( including myself ) to start off.

in the meantime i will take a look of your code ...

Share on other sites
rayan14    100
thank you very much skiritis. you cant imagine how much i appreciate it!

i am waiting very excited to see if you can help me so i can go past this bug

thanks alot!

Share on other sites
GamerSg    378
If by global rotation you mean rotate every object, there is a simple solution. You rotate your camera in the opposite way. Still that means you have to do your rotation before drawing your objects in your loop.

Try to understand how OpenGL works,
At this point your object is rasterized, turned to pixels, you can no longer change this object for this frame. Only thing which could happen is another object closer to the camera is rasterized and it overwrites the pixels.

The only 2 ways you could rotate every object in the world are as follows
1) rotate your camera in the opposite direction.
2) apply your rotation calculations to every object in the world.

Obviously the former is easier/faster to do.

Share on other sites
rayan14    100

Can you demonstrate me how i can do this in the code that i have provided? My OpenGL knowledge is not very stable and im trying my best to have a sample for the contest entry before 30th... i know im going to take last palce but i just want to do it for my pleasure

thanks alot :)

Share on other sites
rayan14    100
How can i change the code so i can make it that i dont need to check if the rotation is negative?

Share on other sites
GamerSg    378
Dont really have much time now, but in general, you could do this. Ive not touched Transfomations in a long time so i might be wrong, but i believe it should work.

float[4] globalRotation;

loop every frame
{
//do this here if you want objects to rotate around camera
//glRotatefv(globalRotation);
for every object
glPushMatrix();
glTranslatef(ObjectPosition)
//do this here if you want objects to around their own axis
//glRotatefv(globalRotation);
glRotatef(localObjectRotation);
glPopMatrix();
end for

}

Share on other sites
rayan14    100
Thank you very much!! can someone please also help me with the exact code that i have provided so that i can remove the if?

Thank you very much!

rayan14    100

Share on other sites
Ezbez    1164
First off, give us some time! You've been stuck on this for 2 months now, you say, so surely you could wait more than 2 hours before bumping your post (say, until it is actually push off the front page?).

Secondly, no one really wants to sort through your entire code base and find the function/section that you are talking about. Can you post that code here directly yourself? You can just copy-and-paste it into a post, and put it between [source] and [/source] tags. Try to give us as little as possible; one or two functions should be enough.

Share on other sites
rayan14    100
Thank you for the reply very much. I am sorry for my bad behaviour.

I believe this section of the code needs to be fixed:

bool Cylinder::ProcessMessage(U32 msg, MsgParam param1, MsgParam param2)
{
bool bHandled = false;

switch (msg)
{
case MSG_TRANSLATE_ALONG_LENGTH:
glTranslatef(0.0f, 0.0f, param1.f * m_lfHeight);
bHandled = true;
break;

case MSG_GET_LENGTH:
*(param1.plf) = m_lfHeight;
bHandled = true;
break;

case MSG_ROTATE_CURRENT_STATE:
if (param1.f > 0)
{
glRotatef(m_rotx, param1.f, 0.0f, 0.0f);
glRotatef(m_roty, 0.0f, param1.f, 0.0f);
glRotatef(m_rotz, 0.0f, 0.0f, param1.f);
}
else
{
glRotatef(m_rotz, 0.0f, 0.0f, param1.f);
glRotatef(m_roty, 0.0f, param1.f, 0.0f);
glRotatef(m_rotx, param1.f, 0.0f, 0.0f);
}
bHandled = true;
break;

case MSG_INCR_LENGTH: m_lfHeight++; bHandled = true; break;
case MSG_ACCUM_LENGTH: m_lfHeight += param1.f; bHandled = true; break;
}

if (!bHandled)
bHandled = GLuObj::ProcessMessage(msg, param1, param2);

return bHandled;
}

i want to remove the if statement that checks if rotation is positive

Share on other sites
skiritis    144
your archive ( OGL ) is broken

Share on other sites
rayan14    100
Quote:
 Original post by skiritisyour archive ( OGL ) is broken

thank you very much Skirtis; it appears that u are the only one who bothered to check the source so far... :) i really appreciate it.

I fixed the problem, please try again :)

Share on other sites
I think the solution to the real problem is Cylert (pemoline), Dexedrine (dextroamphetamine), or Ritalin (methylphenidate).

rayan14    100
..

any help guys?

Share on other sites
deepsender    100
Here is a simplified (pseudo code) version of my own drawing function in a flight sim that I am writing. Notice how there is a camera to define how all other objects will be rotated/translated.

int DrawGLScene(GLvoid){	glViewport(0, 0, xres, yres);	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	gluPerspective(45.0f, x_res/y_res, 1, 10000);	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();	gluLookAt(	camera_position[0],	camera_position[1],	camera_position[2],	camera_direction[0],	camera_direction[1],	camera_direction[2],	0, 1, 0);	glLightfv(GL_LIGHT1, GL_POSITION, your_light);	//Draw all objects here.	draw_world();	return TRUE;}

Share on other sites
silvermace    634
Hey kid [smile] skiritis asked me to help out, so here I am. I can't really understand what your problem is, your explanation is lacking in the question/information respect. However, there are a few things I can point out which may help.

The function ChangeSize, there is no indication as to when that function gets called (apart from the name implying some order), the issue here that it changes the OpenGL state and your rendering function is state sensitive (see below). One option would be to not register ChangeSize with GLUT and manually call it at the beginning of the RenderScene function.

The RenderScene function is state sensitive, that is, the resulting state of OpenGL of the next call to RenderScene is dependent on state just after the current RenderScene call, this is not necessarily a bad thing, but in your case, it looks accidental (because you seem to be tracking absolute rotations using the global variables xRot, yRot and the Visual object's local state variables etc.).

You can make RenderScene self-contained by calling glMatrixMode(GL_MODELVIEW) followed by glLoadIdentity() just before your first call to glPushMatrix in the RenderScene function. After you have done this, try removing the negative check and see if that is the behavior you require.

Hope this helps, I will take another look later tonight.

Share on other sites
rayan14    100
Hello everybody & silvermance

Look at www.albayoung.com/kosta/OGL2.zip . If you run it, you will see that as the one cylinder moves around, it almost never intersects the other cylinder. This is the wrong behavior. If you run the project from the original post (without your suggested changes, www.albayoung.com/kosta/OGL.zip ) the two cylinders always intersect. This is the correct behavior.

Let me know if you need more details

Once again, thank you all

Share on other sites
Guest Anonymous Poster

rayan14    100
:(

Share on other sites
skow    248
I would suggest bumping your thread less frequently as others have suggested, it is hurting your ability to get feedback.

I don’t have as new of a version of Visual Studio so I can’t compile your code. But regardless, slow down and explain a little clearer what your issue is.

By global rotation do you mean the ability to rotate an object around a point rather than rotating it about its own axis? Please explain clearly what you need to do (with an example), and I will try and help you.

Share on other sites
rayan14    100
im sorry but nobody wants to help me and the date is approaching :(

Share on other sites
Guest Anonymous Poster
"Scope1" is the first project ( OGL.zip. "Scope2" is the second one (OGL2.zip). The desired behavior of the program is that the two cylinders are always touching - one cylinder stays in the same spot (but grows in length), and one cylinder moves around, but always intersects the other (stationary) cylinder.

1) Run Scope1
2) Press the "Go" button
3) Press the "up arrow" on the keyboard once (now you can see both cylinders)
4) Notice that the two cylinders always intersect

Run the steps above on Scope 2 and you will notice in step 4 that the cylinders don't always intersect.

Share on other sites
skow    248

As I said in my prior post I am NOT able to compile your code, and with the description you gave I really don’t know much, but here it goes. I really suggest you read what other people post if they are trying to help.

I am going to assume you just want the second cylinder to rotate around the first one.

Code:

DrawCylinder(); //The middle cylinder, drawn at 0,0,0
glPushMatrix();
glTranslatef(); //Translate the distance out the other one is growing minus the second cylinders radius
glRotatef(); //Rotate the cylinder around the center
DrawCylinder(); //The second cylinder, drawn at 0,0,0 (the rotate and transform will move it)
glPopMatrix(); //Done

If that is not what you need, well it is a shame you didn’t give me more details like I asked.

Create an account

Register a new account

• Similar Content

• I'm trying to get some legacy OpenGL code to run with a shader pipeline,
The legacy code uses glVertexPointer(), glColorPointer(), glNormalPointer() and glTexCoordPointer() to supply the vertex information.
I know that it should be using setVertexAttribPointer() etc to clearly define the layout but that is not an option right now since the legacy code can't be modified to that extent.
I've got a version 330 vertex shader to somewhat work:
#version 330 uniform mat4 osg_ModelViewProjectionMatrix; uniform mat4 osg_ModelViewMatrix; layout(location = 0) in vec4 Vertex; layout(location = 2) in vec4 Normal; // Velocity layout(location = 3) in vec3 TexCoord; // TODO: is this the right layout location? out VertexData { vec4 color; vec3 velocity; float size; } VertexOut; void main(void) { vec4 p0 = Vertex; vec4 p1 = Vertex + vec4(Normal.x, Normal.y, Normal.z, 0.0f); vec3 velocity = (osg_ModelViewProjectionMatrix * p1 - osg_ModelViewProjectionMatrix * p0).xyz; VertexOut.velocity = velocity; VertexOut.size = TexCoord.y; gl_Position = osg_ModelViewMatrix * Vertex; } What works is the Vertex and Normal information that the legacy C++ OpenGL code seem to provide in layout location 0 and 2. This is fine.
What I'm not getting to work is the TexCoord information that is supplied by a glTexCoordPointer() call in C++.
Question:
What layout location is the old standard pipeline using for glTexCoordPointer()? Or is this undefined?

Side note: I'm trying to get an OpenSceneGraph 3.4.0 particle system to use custom vertex, geometry and fragment shaders for rendering the particles.

• 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!

• 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.

• 12
• 10
• 18
• 9
• 10