Can I have some Sample Code? (OpenGL, glDrawPixels();)

This is a discussion on Can I have some Sample Code? (OpenGL, glDrawPixels();) within the Game Programming forums, part of the General Programming Boards category; A vertex buffer simply holds all the vertices of the object in question. It will also hold normal information, diffuse ...

  1. #16
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    A vertex buffer simply holds all the vertices of the object in question. It will also hold normal information, diffuse color, specular color, and/or multiple sets of texture coordinates.
    Holds all these things in video memory, so there is less strain on the processor, right?

    I'm trying to understand more the theory of this idea, I don't want to look at the code until I understand what exactly it is doing , I'll keep researching about vertex buffers and such. Thanks for help Bubba, I'll post again with any questions

  2. #17
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Here are the errors

    Code:
    --------------------Configuration: NeHeGL - Win32 Debug--------------------
    Compiling...
    Example.cpp
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(20) : error C2969: syntax error : ';' : expected member function definition to end with '}'
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(89) : error C2143: syntax error : missing ')' before '{'
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(137) : error C2969: syntax error : ';' : expected member function definition to end with '}'
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(138) : error C2059: syntax error : 'constant'
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(138) : error C2040: 'tu' : 'int (void)' differs in levels of indirection from 'float'
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(139) : error C2059: syntax error : 'constant'
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(139) : error C2040: 'tv' : 'int (void)' differs in levels of indirection from 'float'
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(139) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(139) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(167) : error C2838: illegal qualified name in member declaration
    c:\documents and settings\jonathan\my documents\nehegl\example.cpp(32) : error C2065: 'window' : undeclared identifier
    c:\documents and settings\jonathan\my documents\nehegl\example.cpp(32) : error C2258: illegal pure syntax, must be '= 0'
    c:\documents and settings\jonathan\my documents\nehegl\example.cpp(32) : error C2501: 'g_window' : missing storage-class or type specifiers
    c:\documents and settings\jonathan\my documents\nehegl\example.cpp(33) : error C2065: 'keys' : undeclared identifier
    c:\documents and settings\jonathan\my documents\nehegl\example.cpp(33) : error C2258: illegal pure syntax, must be '= 0'
    c:\documents and settings\jonathan\my documents\nehegl\example.cpp(33) : error C2501: 'g_keys' : missing storage-class or type specifiers
    c:\documents and settings\jonathan\my documents\nehegl\example.cpp(36) : error C2258: illegal pure syntax, must be '= 0'
    c:\documents and settings\jonathan\my documents\nehegl\example.cpp(36) : error C2501: 'angle' : missing storage-class or type specifiers
    c:\documents and settings\jonathan\my documents\nehegl\example.cpp(38) : error C2059: syntax error : 'constant'
    c:\documents and settings\jonathan\my documents\nehegl\example.cpp(39) : error C2059: syntax error : 'constant'
    c:\documents and settings\jonathan\my documents\nehegl\example.cpp(40) : error C2059: syntax error : 'constant'
    c:\documents and settings\jonathan\my documents\nehegl\example.cpp(41) : error C2059: syntax error : 'constant'
    c:\documents and settings\jonathan\my documents\nehegl\example.cpp(42) : error C2059: syntax error : 'constant'
    c:\documents and settings\jonathan\my documents\nehegl\example.cpp(43) : error C2059: syntax error : 'constant'
    c:\documents and settings\jonathan\my documents\nehegl\example.cpp(45) : error C2059: syntax error : 'return'
    c:\documents and settings\jonathan\my documents\nehegl\example.cpp(45) : error C2238: unexpected token(s) preceding ';'
    c:\documents and settings\jonathan\my documents\nehegl\example.cpp(48) : error C2628: 'Vertex3D' followed by 'void' is illegal (did you forget a ';'?)
    c:\documents and settings\jonathan\my documents\nehegl\example.cpp(49) : error C2784: 'struct Vertex3D __cdecl Deinitialize(void)' : could not deduce template argument for 'struct Vertex3D' from 'void'
    c:\documents and settings\jonathan\my documents\nehegl\example.cpp(49) : error C2785: 'struct Vertex3D __cdecl Deinitialize(void)' and 'void __cdecl Deinitialize(void)' have different return types
            c:\documents and settings\jonathan\my documents\nehegl\example.cpp(48) : see declaration of 'Deinitialize'
    c:\documents and settings\jonathan\my documents\nehegl\example.cpp(53) : fatal error C1903: unable to recover from previous error(s); stopping compilation
    Error executing cl.exe.
    
    NeHeGL.exe - 30 error(s), 0 warning(s)
    Last edited by Shamino; 10-22-2005 at 06:20 PM.

  3. #18
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    To Show that I am not incompetant, I got rid of all but 1...

    Code:
    --------------------Configuration: NeHeGL - Win32 Debug--------------------
    Compiling...
    Example.cpp
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(22) : error C2969: syntax error : ';' : expected member function definition to end with '}'
    Error executing cl.exe.
    
    NeHeGL.exe - 1 error(s), 0 warning(s)
    The error is Right here in this area, or so it says..

    Code:
         Vector3(const Vector3 &v)
         {
           x=v.x;
    	   y=v.y;
    	   z=v.z;
         }
    
         Vector3(void):x(0.0f),y(0.0f),z(0.0f);
         Vector3(float vx,float vy,float vz):x(vx),y(vy),z(vz) {}
    Don't really know what the dilio is :d

  4. #19
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Fixed it,
    Code:
         Vector3(void):x(0.0f),y(0.0f),z(0.0f) {}
         Vector3(float vx,float vy,float vz):x(vx),y(vy),z(vz) {}
    two more errors
    Code:
    --------------------Configuration: NeHeGL - Win32 Debug--------------------
    Compiling...
    Example.cpp
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(111) : error C2065: 'sqrt' : undeclared identifier
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(111) : error C2065: 'Length' : undeclared identifier
    Error executing cl.exe.
    
    NeHeGL.exe - 2 error(s), 0 warning(s)
    Are we missing a math file? or is something just not declaring correctly?

    Included math.h, got rid of the sqrt problem, but Length is still unidentified, moving on...

    Ahhh, length, not Length...

    teehee, lots of lil screwups here and there, i feel almighty debugging bubba's code

    Code:
    --------------------Configuration: NeHeGL - Win32 Debug--------------------
    Compiling...
    Example.cpp
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(111) : warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(145) : error C2065: '_specular' : undeclared identifier
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(146) : error C2065: '_tv' : undeclared identifier
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(146) : warning C4244: 'initializing' : conversion from 'int' to 'float', possible loss of data
    Error executing cl.exe.
    
    NeHeGL.exe - 2 error(s), 2 warning(s)
    Bugs are now right here --->

    Code:
    struct Vertex3D
    {
      Vector3 Model;
      Vector3 World;
      Vector3 View;
      Vector3 Pos;
      DWORD Diffuse;
      DWORD Specular;
      float tu,tv;
    
      Vertex3D(void):Model(Vector3(0.0f,0.0f,0.0f)),
                               World(Vector3(0.0f,0.0f,0.0f)),
                               View(Vector3(0.0f,0.0f,0.0f)),
                               Pos(Vector3(0.0f,0.0f,0.0f)),
                               Diffuse(0),
                               Specular(0),
                               tu(0.0f),
                               tv(0.0f)  {}
    
      Vertex3D(Vector3 _pos,DWORD _diffuse=0,DWORD Specular=0,
                      float _tu=0.0f,float tv=0.0f):Pos(_pos),
                      Diffuse (_diffuse),Specular(_specular),tu(_tu),
                      tv(_tv) {}
    };
    Workin on it...
    Last edited by Shamino; 10-22-2005 at 06:02 PM.

  5. #20
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    It runs now, got rid of all those underscores,, and fixed specular to Specular....

    Go me, i probably broke it though, bubba, thoughts?

    All I need now is more information on how to use it in opengl...

    lol, ur not the opengl guy so you can't give me a 100% answer, or is this more of a straight up C++ issue? i think it may be.... Seeing as how your vertex3d classes n stuff don't use OGL it just uses c++...

    can you give me a more detailed function call? etc? etc? words on how to actually make use of that class... Thanks bubba
    Last edited by Shamino; 10-22-2005 at 09:40 PM.

  6. #21
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    I tried putting this in my main cpp file

    Code:
    	VertexBuffer<Vertex3D> MyVertexBuffer;
    I get these errors...

    Code:
    --------------------Configuration: NeHeGL - Win32 Debug--------------------
    Compiling...
    Example.cpp
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(111) : warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(156) : error C2065: 'null' : undeclared identifier
            c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(156) : while compiling class-template member function '__thiscall VertexBuffer<struct Vertex3D>::VertexBuffer<struct Vertex3D>(void)'
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(156) : error C2440: 'initializing' : cannot convert from 'int' to 'struct Vertex3D *'
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
            c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(156) : while compiling class-template member function '__thiscall VertexBuffer<struct Vertex3D>::VertexBuffer<struct Vertex3D>(void)'
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(156) : error C2439: 'm_pVertexData' : member could not be initialized
            c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(151) : see declaration of 'm_pVertexData'
            c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(156) : while compiling class-template member function '__thiscall VertexBuffer<struct Vertex3D>::VertexBuffer<struct Vertex3D>(void)'
    Error executing cl.exe.
    
    NeHeGL.exe - 3 error(s), 1 warning(s)
    Lesseeee.....
    Last edited by Shamino; 10-23-2005 at 07:00 PM.

  7. #22
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Fixed, from this

    Code:
    template <class T> class VertexBuffer
    {
      T *m_pVertexData;
      DWORD m_dwNumVertices;
      DWORD m_dwStride;
      
      public:
         VertexBuffer(void):m_pVertexData(null),m_dwNumVertices(0),m_dwStride(0) {}
    
         bool Create(DWORD _numverts,DWORD _stride);
         T *Lock(void) {return m_pVertexData;}
    };
    To this

    Code:
    template <class T> class VertexBuffer
    {
      T *m_pVertexData;
      DWORD m_dwNumVertices;
      DWORD m_dwStride;
      
      public:
         VertexBuffer(void):m_pVertexData(0),m_dwNumVertices(0),m_dwStride(0) {}
    
         bool Create(DWORD _numverts,DWORD _stride);
         T *Lock(void) {return m_pVertexData;}
    };
    So I am able to create my own vertex buffer, now what can I do with it? examples pleeease!!
    Last edited by Shamino; 10-23-2005 at 07:01 PM.

  8. #23
    ---
    Join Date
    May 2004
    Posts
    1,379
    Have you even tried the ARB extensions to see if they work? It would save you a lot of trouble.

  9. #24
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    yeah they don't work on the schools video cards, thus why im going to try to use this software version

    I put this line in to try to make use of my code and draw something, I know im missing the index buffer, dunno how to do that....

    Code:
    bool Draw(VertexBuffer *pVB,IndexBuffer *pIB=NULL,BYTE PrimitiveType=3DPRIMS_POINT);
    And obviously im going to get this error...

    Code:
    --------------------Configuration: NeHeGL - Win32 Debug--------------------
    Compiling...
    Example.cpp
    c:\documents and settings\jonathan\my documents\nehegl\vertexbuffer.h(111) : warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
    C:\Documents and Settings\Jonathan\My Documents\NeHeGL\Example.cpp(71) : error C2061: syntax error : identifier 'IndexBuffer'
    C:\Documents and Settings\Jonathan\My Documents\NeHeGL\Example.cpp(71) : error C2059: syntax error : 'bad suffix on number'
    Error executing cl.exe.
    
    NeHeGL.exe - 2 error(s), 1 warning(s)
    Missing index buffer thingy, thats all i need now i think.....
    How do I do this index buffer thing, i know you gave me the theory behind it, but i'm talking code wise :d
    Last edited by Shamino; 10-23-2005 at 07:48 PM.

  10. #25
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    That code was not complete. But it should serve as a starting point. You need to define primitive types and the like. Also you need to know how to send the vertex data to OpenGL or at least transform the vertices yourself. I cannot give you the complete code to a software vertex buffer system. I don't even know how OpenGL works because frankly I don't care for it or how it works. I'm pure Direct3D and DirectX.

  11. #26
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Hmmmmmmmm.....

    so i need to define a primitive... by giving it vertices..... in a structure or something like that....

    make v1-v4...

    make
    v1= 20, 20...
    v2 = -20, 20..
    v3 = -20, -20..
    v4 = 20, -20...

    thats my 20x20 quad primitive... thats what im getting out of this.....

    or wait. I just make....

    v1 = 1
    v2 = 2
    v3 = 3
    v4 = 4

    so on, so i declare like every possible vertice... (for an index buffer)

    and then for a GLprimitivequad, or whatever.... just call out 4 vertices from the index.... to create the quad... meh, i'm lost for now... I'll just learn the ARB extensions at home and hope to god i never have to use a video card thats too poopy for vbo's....

  12. #27
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    Quote Originally Posted by Shamino
    Ultimately, what i need to do, is change a certain set of pixels (20x20) green, which arent outlined by a polygon of any sort....without killing my system... I really don't know where to look anymore
    So... you know exactly what pixels you need to change? If so, then change to a 2D ortho perspective with Width and Height the same as the window and draw a single poly untextured 20x20.

    If you want a way to optimize the change from 2D and 3D I can help on that.

  13. #28
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    I'm already in 2d orthoscopic....

    Making quads the "normal" way is what im trying to avoid, because ultimately when you end up with alot of them it lags, unless you're using vertex buffer objects... or vertex arrays, which is what i'm trying to learn how to do....

  14. #29
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    Are they all the same size? You could use a DisplayList to create one, and then just repeat it. That should be fast enough.

    Code:
    unsigned int ID;  //this is a unique ID for the list, like a texture ID
    ID = glGenLists(1);
    glNewList(ID, GL_COMPILE);
       glBegin(GL_QUADS);
       //Draw your model here
       glEnd();
    glEndList();
    
    //------------------------------------------------
    
    //Anywhere you want to draw the above object, just type
    
    glCallList(ID);
    A display list creates a cache of any commands you insert inside of this list so the can be executed quickly. Vertex arrays are on par with Display Lists as far as speed goes, vertex arrays allow you to alter the data during the program, you have to delete the display list and remake it to alter the data there. The tradeoff for this reduced flexability is that display lists are very simple.
    Last edited by Eber Kain; 10-24-2005 at 08:58 AM.

  15. #30
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    so display lists basically work the same way as vertex arrays?
    hm

    they are all the same size, but they arent all in the same location, therefore it needs to be dynamic and changeable.......... right?

Page 2 of 7 FirstFirst 1234567 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SMS sample code
    By hagenuk in forum C Programming
    Replies: 1
    Last Post: 05-30-2008, 12:47 PM
  2. Sample code please help!!!
    By aewing30 in forum C Programming
    Replies: 6
    Last Post: 05-29-2008, 11:51 AM
  3. The code sample of classes in the tutorial. :o
    By Wall in forum C++ Programming
    Replies: 3
    Last Post: 08-20-2004, 10:18 AM
  4. looking for book with sample code
    By stella in forum C++ Programming
    Replies: 5
    Last Post: 06-25-2003, 11:48 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21