Sign in to follow this  

OpenGL opengl and c++

This topic is 1796 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, i recently bought the official book (8th edition) from safari books online and i have some questions:

 

1. i cant get any compiler to run opengl on c++, can you give me one that i should use? and how can i get it to work? (glut not working either)

 

2. where can i get the sample from the book? i mean there are function's that they make and i wanna see how they make it.

 

3. the book is a little hard for me because im kind of new to all that stuff (not programming) and i wanted to ask you how can i

learn what is all that shader stage's and stuff because it's really hard for me to get it and im trying really hard..

is there a site or something that explain it a little bit more understandable for me?

(my english is not that good and i some words may cause me some problems to understand and i really want to understand all of the book..)

 

 

if you guys could help me out that would be great!

i really need help on the third one though that's my priority :)

 

thanks!

Share this post


Link to post
Share on other sites

Firstly, i've never read he book you're talking about, so i can't help you with those functions.

 

Now for the compilers.

If you're using windows, you can download the Microsoft Visual C++ Express 2010/2012 for free.

If not, then you can download code::blocks and use the MinGW compiler that comes with it.

 

If you can't make GLUT work, and you get linker errors, then you have to put the glut32.lib (or whatever it's called) in your compiler linker path.

 

For tutorials, you can go to http://nehe.gamedev.net/, although the tutorials are outdated, they still provide some good information.

For newer, shader based, OpenGL, you can go to http://www.arcsynthesis.org/gltut/index.html which has very useful tutorials about 3D programming. It uses GLUT in the examples though.

 

Also, these tutorials provide source code to compile and modify yourself, to try new things.

 

There are more compilers/IDEs, and sites, but i think these are the main used ones.

 

Hope it helps.

Share this post


Link to post
Share on other sites

If you need glu32.lib, chances are you are using legacy OpenGL. If you do that, make sure you understand what it means.

 

In the same way, don't spend too much time on the NEHE tutorials until you know about legacy OpenGL.

Share this post


Link to post
Share on other sites

i really dont knot what i need actually :\

i need glut i guess but how do i add it? (is it glu32.lib?)

 

if not, what is it and where can i find it and make it to work with my compiler?

 

thanks!

Share this post


Link to post
Share on other sites

AS larspensjo said, GLU and GLUT are deprecated, along with the NeHe tutorials (i just mentioned them, because they still provide some insight).

It's okay if you use them when you're starting learning, but they are no longer used in modern OpenGL.

 

The glu32.lib goes into the compiler lib folder. Then to use it in a project, you have to go to the project properties (this depends on the editor), and add the glu32.lib in the linker search path. Visual C++ has something like "Additional linker dependencies" in the project options, under the "Linker" tab.

Share this post


Link to post
Share on other sites

I'm not an expert but this is what works for me:

 

to use OpenGL you need to #include <GL\GL.h> and <GL\GLU.h>

 

and also you need to link to OpenGL32.lib and glu32.lib (in visual studio 2012, Project > Properties > Configuration Properties > Linker > Input > Additional Dependencies )

 

GL and GLU are part of OpenGL (correct me if I'm wrong!  ), GLUT is an external library so it's your choice if you want to use it. but if you use OpenGL you will need a library to set up your windows (so that you can use OpenGL to draw in them ) GLUT is an example of this.

 

the most useful book I came across is OpenGL Programming Guide.

 

PS. if you are a student you can use www.dreamspark.com to get Visual Studio for free

 

good luck ^^

Edited by hikarihe

Share this post


Link to post
Share on other sites

sorry i didnt know the differences between glu and glut.

 

so glu32.lib != GLUT?

if so what should i do to make glut to work with my compiler?

 

sorry for the newbie question's its just that im learning from the new book they going to release and there isn't any example's online (the site is down for like a month now) and

they using separate files to compile the code.. (the files that i need to see is not in the book but online.. :\ )

 

and if someone could help me out and tell me how can i learn better from this book (like how to get the online example if the main page of the site is down) that would be great! :)

 

thanks a lot for your help!

Share this post


Link to post
Share on other sites

OpenGL is the API.

Both GLU and GLUT are external libraries that provide functionality (and easiness of use) to OpenGL.

 

GLU serves many purposes, which can range from setting perspectives, building textures & mipmaps, creating predifined meshes (cone, etc) and more.

GLUT is a window management library for OpenGL. It allows you to create a window in any OS without using OS dependant code, hence it is portable.

 

glu32.lib is the GLU library.

glut32.lib is the GLUT library

 

And yes, the path for Visual C++ mentioned by hikarihe is correct, and is the same for VC++ 2010 Express.

I don't know if you need to be a student at that site though. When i downloaded Visual C++ 2010 Express i think it was on the Microsoft website (i still use 2010).

Share this post


Link to post
Share on other sites

Thanks a lot!

what do you recommend VC++ 2010 or Code::Blocks?

 

thanks again! :)

Share this post


Link to post
Share on other sites

For Windows, i prefer VC++ 2010/2012. For any other OS Code::Blocks is a choice, although i think there's some other good IDE for MacOSX that i don't remember the name.

Share this post


Link to post
Share on other sites

Thanks !

 

I have another question because i figured that my knowledge on C++ is not enough.

 

What should i learn in C++ to start developing good games and understand all the concept of it?

 

do you recommend C++ or Java to build games based on Opengl? (or other language's like C#)

 

(the main question i really want you guys to answer me is what should i learn in C++ to start developing (leaving the Opengl out))

 

Thanks for all your help that's really helpful!

Share this post


Link to post
Share on other sites

For the language I'll always advise C++, because that's probably the most used language, especially in game development, not to mention it's my favorite language, and the one i always use. But don't let me stop you from trying other languages, just ask other people and they will surely point out the good in any of them.

I know you can use LWJGL (which is a way to use OpenGL (and more, i think) on Java).

 

Now, if you don't know C++ yet, or  you think you don't know enough (and assuming that's the language you're going to learn), for now you should set apart the idea of making a game.

First you must use how to program in C++, and i mean really learn it (advanced stuff like pointers, classes, inheritance, templates, overloading, etc).

If you want online tutorials on C++, you can go to http://www.cplusplus.com/doc/tutorial/ and follow the tutorials there. They point out most of the C++ features you should know, although some of them take a lot of practice to perfect (like pointers).

 

Also, you should read about design patterns (after getting a good grasp on the language). They will help you designing better code.

 

After you have a good grasp in the language you can then start learning OpenGL.

Also, it would do you good to decide whether you want to learn the deprecated OpenGL functionality or not. I can't really said if it helps or not, but when i first learned OpenGL, i started there, so maybe when i learned shader based OpenGL the learning curve wasn't that difficult.

I'll let others advise more on this.

 

More than this, remember that a game is not only graphics (although graphics is a big part of them).

You could then learn OpenAL for audio (or FMOD, for example), DirectInput (on Windows only) for input, and a lot more.

 

Other than that i can only say to keep practicing. As they say, practice makes perfect (or at least close).

Share this post


Link to post
Share on other sites

Thanks a lot!!

That's really helpful! :)

I will finish learning C++ and then start learning some design patterns like you said i think that would be great for me :)

Share this post


Link to post
Share on other sites

There are some really nice design patterns, and many of them are not limited to C++.

 

From my own experience, I find it hard to read about a design pattern and then start to use it. I almost always have to try to solve a problem first, develop an ugly solution, and then read about the pattern that shows how it really should have been done. Learning by mistakes.

 

C++ is a complicated language. Very powerful, but also with many opportunities to go wrong. To learn it, spend as much time as possible, and learn from mistakes.

Share this post


Link to post
Share on other sites

You're right, but i also think that if you starts learning about design patterns at the beginning (not exactly using them at the start, but knowing they exist), then you'd be able to adapt to them earlier.

 

I found it hard to start using them, because when i started programming i didn't even know they exist, so when i read them up, i found it difficult to start applying them, simply because i was not used to them.

 

But yes, one should always learning by trying (and failing).

Share this post


Link to post
Share on other sites

This topic is 1796 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 xhcao
      Does sync be needed to read texture content after access texture image in compute shader?
      My simple code is as below,
      glUseProgram(program.get());
      glBindImageTexture(0, texture[0], 0, GL_FALSE, 3, GL_READ_ONLY, GL_R32UI);
      glBindImageTexture(1, texture[1], 0, GL_FALSE, 4, GL_WRITE_ONLY, GL_R32UI);
      glDispatchCompute(1, 1, 1);
      // Does sync be needed here?
      glUseProgram(0);
      glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer);
      glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                                     GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, texture[1], 0);
      glReadPixels(0, 0, kWidth, kHeight, GL_RED_INTEGER, GL_UNSIGNED_INT, outputValues);
       
      Compute shader is very simple, imageLoad content from texture[0], and imageStore content to texture[1]. Does need to sync after dispatchCompute?
    • By Jonathan2006
      My question: is it possible to transform multiple angular velocities so that they can be reinserted as one? My research is below:
      // This works quat quaternion1 = GEQuaternionFromAngleRadians(angleRadiansVector1); quat quaternion2 = GEMultiplyQuaternions(quaternion1, GEQuaternionFromAngleRadians(angleRadiansVector2)); quat quaternion3 = GEMultiplyQuaternions(quaternion2, GEQuaternionFromAngleRadians(angleRadiansVector3)); glMultMatrixf(GEMat4FromQuaternion(quaternion3).array); // The first two work fine but not the third. Why? quat quaternion1 = GEQuaternionFromAngleRadians(angleRadiansVector1); vec3 vector1 = GETransformQuaternionAndVector(quaternion1, angularVelocity1); quat quaternion2 = GEQuaternionFromAngleRadians(angleRadiansVector2); vec3 vector2 = GETransformQuaternionAndVector(quaternion2, angularVelocity2); // This doesn't work //quat quaternion3 = GEQuaternionFromAngleRadians(angleRadiansVector3); //vec3 vector3 = GETransformQuaternionAndVector(quaternion3, angularVelocity3); vec3 angleVelocity = GEAddVectors(vector1, vector2); // Does not work: vec3 angleVelocity = GEAddVectors(vector1, GEAddVectors(vector2, vector3)); static vec3 angleRadiansVector; vec3 angularAcceleration = GESetVector(0.0, 0.0, 0.0); // Sending it through one angular velocity later in my motion engine angleVelocity = GEAddVectors(angleVelocity, GEMultiplyVectorAndScalar(angularAcceleration, timeStep)); angleRadiansVector = GEAddVectors(angleRadiansVector, GEMultiplyVectorAndScalar(angleVelocity, timeStep)); glMultMatrixf(GEMat4FromEulerAngle(angleRadiansVector).array); Also how do I combine multiple angularAcceleration variables? Is there an easier way to transform the angular values?
    • By dpadam450
      I have this code below in both my vertex and fragment shader, however when I request glGetUniformLocation("Lights[0].diffuse") or "Lights[0].attenuation", it returns -1. It will only give me a valid uniform location if I actually use the diffuse/attenuation variables in the VERTEX shader. Because I use position in the vertex shader, it always returns a valid uniform location. I've read that I can share uniforms across both vertex and fragment, but I'm confused what this is even compiling to if this is the case.
       
      #define NUM_LIGHTS 2
      struct Light
      {
          vec3 position;
          vec3 diffuse;
          float attenuation;
      };
      uniform Light Lights[NUM_LIGHTS];
       
       
    • By pr033r
      Hello,
      I have a Bachelor project on topic "Implenet 3D Boid's algorithm in OpenGL". All OpenGL issues works fine for me, all rendering etc. But when I started implement the boid's algorithm it was getting worse and worse. I read article (http://natureofcode.com/book/chapter-6-autonomous-agents/) inspirate from another code (here: https://github.com/jyanar/Boids/tree/master/src) but it still doesn't work like in tutorials and videos. For example the main problem: when I apply Cohesion (one of three main laws of boids) it makes some "cycling knot". Second, when some flock touch to another it scary change the coordination or respawn in origin (x: 0, y:0. z:0). Just some streng things. 
      I followed many tutorials, change a try everything but it isn't so smooth, without lags like in another videos. I really need your help. 
      My code (optimalizing branch): https://github.com/pr033r/BachelorProject/tree/Optimalizing
      Exe file (if you want to look) and models folder (for those who will download the sources):
      http://leteckaposta.cz/367190436
      Thanks for any help...

    • By Andrija
      I am currently trying to implement shadow mapping into my project , but although i can render my depth map to the screen and it looks okay , when i sample it with shadowCoords there is no shadow.
      Here is my light space matrix calculation
      mat4x4 lightViewMatrix; vec3 sun_pos = {SUN_OFFSET * the_sun->direction[0], SUN_OFFSET * the_sun->direction[1], SUN_OFFSET * the_sun->direction[2]}; mat4x4_look_at(lightViewMatrix,sun_pos,player->pos,up); mat4x4_mul(lightSpaceMatrix,lightProjMatrix,lightViewMatrix); I will tweak the values for the size and frustum of the shadow map, but for now i just want to draw shadows around the player position
      the_sun->direction is a normalized vector so i multiply it by a constant to get the position.
      player->pos is the camera position in world space
      the light projection matrix is calculated like this:
      mat4x4_ortho(lightProjMatrix,-SHADOW_FAR,SHADOW_FAR,-SHADOW_FAR,SHADOW_FAR,NEAR,SHADOW_FAR); Shadow vertex shader:
      uniform mat4 light_space_matrix; void main() { gl_Position = light_space_matrix * transfMatrix * vec4(position, 1.0f); } Shadow fragment shader:
      out float fragDepth; void main() { fragDepth = gl_FragCoord.z; } I am using deferred rendering so i have all my world positions in the g_positions buffer
      My shadow calculation in the deferred fragment shader:
      float get_shadow_fac(vec4 light_space_pos) { vec3 shadow_coords = light_space_pos.xyz / light_space_pos.w; shadow_coords = shadow_coords * 0.5 + 0.5; float closest_depth = texture(shadow_map, shadow_coords.xy).r; float current_depth = shadow_coords.z; float shadow_fac = 1.0; if(closest_depth < current_depth) shadow_fac = 0.5; return shadow_fac; } I call the function like this:
      get_shadow_fac(light_space_matrix * vec4(position,1.0)); Where position is the value i got from sampling the g_position buffer
      Here is my depth texture (i know it will produce low quality shadows but i just want to get it working for now):
      sorry because of the compression , the black smudges are trees ... https://i.stack.imgur.com/T43aK.jpg
      EDIT: Depth texture attachment:
      glTexImage2D(GL_TEXTURE_2D, 0,GL_DEPTH_COMPONENT24,fbo->width,fbo->height,0,GL_DEPTH_COMPONENT,GL_FLOAT,NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, fbo->depthTexture, 0);
  • Popular Now