Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 30

Thread: No idea how to start

  1. #11
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    19
    Just a quick question: vectors ( with x,y,z) for opengl have no relation to the vectors in c++ right (the "vector<string> words")? Or are they somehow related?

  2. #12
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    899
    No, none whatsoever - and a vector is not an OpenGL concept as well. In mathematics, an n-component vector is an entity of an n-dimensional vector space, i.e. a 3-component vector is an entity of the R^3. A std::vector in C++ is simply a dynamically growing (or shrinking if demanded) container with an internal C-array. C-arrays are also referred to as vectors (or sometimes as fields) but essentially represent nothing else than a contiguous, one-dimensional area in memory.

    Since vectors are used to describe positions and directions in space and linear transformations between vector spaces are an essential concept in computer graphics - as is linear algebra in general - it is no coincidence you have to deal with such entities when doing graphics programming with OpenGL. When you define vertex attributes, you'll do it using vectors. When doing a transformation from object space to eye space, you'll do a linear transformation from R^4 to R^4 using a 4x4 matrix (or 3x4 to spare your shader the 4th row being (0,0,0,1)).
    Last edited by thokra; 07-03-2012 at 12:22 AM. Reason: Clarify OpenGL's relation to vectors.

  3. #13
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    19
    Ok so, I have these boolean arrays created in one of my header files above a bunch of functions that use them:

    bool* keyStates = new bool[256]; // Create an array of boolean values of length 256 (0-255)
    bool* keySpecialStates = new bool[246]; // Create an array of boolean values of length 246 (0-245)

    And for some reason, I get this compiler error:

    error LNK2005: "bool * keyStates" (?keyStates@@3PA_NA) already defined in main.obj
    error LNK2005: "bool * keySpecialStates" (?keySpecialStates@@3PA_NA) already defined in main.obj

    I'm not sure what this means, even after googling it. These are the only declarations of these arrays in the program, they are right before the functions they are used in.

    Help is appreciated!

  4. #14
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655
    Rename your vars with something silly like append AAA to the name to rule out any name collision.
    Maybe your project tries to link the same file twice ?

  5. #15
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    19
    No they're still apparently already defined in main.obj

    If I cut and paste these lines into the .cpp file (this file doesn't contain main, just a bunch of functions) that has all the functions declared in the .h file, the whole thing compiles and works fine. However this feels messy. Is it normal to declare variables like this? or is there a way I can have these in the header file?
    Last edited by Jossos; 07-03-2012 at 03:50 PM.

  6. #16
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,726
    Ok so, I have these boolean arrays created in one of my header files above a bunch of functions that use them:
    OK, it seems clear at this point that you're not very experienced with C/C++. I would strongly advise you to stop working on graphics and spend some time learning the ins and outs of C++. Graphics programming is hard enough; you don't want to compound it by not having firm foundation of how the language you're using works.

    The particular problem you're encountering has to do with the difference between a declaration and a definition in C/C++. You're defining the same global variable in multiple .cpp files (through the inclusion of the same .h). That's not allowed. You are allowed to declare the same global variable in multiple .cpp files, but it can only be defined in one of them. More information can be found here.

    Also, do note that this is an OpenGL forum, not a general programming issues forum.

  7. #17
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    19
    Quote Originally Posted by Alfonse Reinheart View Post
    OK, it seems clear at this point that you're not very experienced with C/C++. I would strongly advise you to stop working on graphics and spend some time learning the ins and outs of C++. Graphics programming is hard enough; you don't want to compound it by not having firm foundation of how the language you're using works.

    The particular problem you're encountering has to do with the difference between a declaration and a definition in C/C++. You're defining the same global variable in multiple .cpp files (through the inclusion of the same .h). That's not allowed. You are allowed to declare the same global variable in multiple .cpp files, but it can only be defined in one of them. More information can be found here.

    Also, do note that this is an OpenGL forum, not a general programming issues forum.
    pfft
    Nahh I'm doing fine. I already got cubes an am about to animate them.

    And sorry i forgot this was opengl specific. I'll try to keep it as such.

  8. #18
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    899
    pfft Nahh I'm doing fine.
    It's always good to arrogantly dismiss a sound advice by an experienced developer which is obviously more than justified...

  9. #19
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    19
    Quote Originally Posted by thokra View Post
    It's always good to arrogantly dismiss a sound advice by an experienced developer which is obviously more than justified...
    I didn't mean to be arrogant, sorry if it seems I was. At the time of reading this, I was (and still am) going strong in openGL, and think I can start creating some interesting programs soon with current knowledge.

  10. #20
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    899
    I don't know about the others, but to me it seemed to be. You need to plan ahead. Most interesting programs aren't easily developed without proper knowledge of the programming language and libraries involved. Otherwise you're going to trip and fall many many times. Personally fully I support Alfonse's suggestion.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •