|
Const pointer to pointer to char problems |
Ariesnl
Member #2,902
November 2002
|
I would like to manage OpenGL shaders in a more C++ and OO way I want to store the shader code into my class and then compile it OpenGL expects a constant pointer to a pointer to a char "const **GLchar" Is there any good way to stuff one into the other ?? Maybe it's me but I don't see it.... 1bool OpenGLShader::Compile()
2{
3 GLchar source[m_vShaderSource.size()+2];
4 vector<GLchar>::const_iterator P = m_vShaderSource.begin();
5 int nIndex =0;
6 while (P!=m_vShaderSource.end())
7 {
8 source[nIndex] = *P;
9 nIndex++;
10 P++;
11 }
12
13 source[nIndex] ='\0'; // <-------
14
15 const GLchar ** pSource = &source; // <--------
16 glShaderSource(m_nShaderIndex, 1, pSource, NULL); // <---------
17
18
19 glCompileShader(m_nShaderIndex);
20 GLint status;
21 glGetShaderiv(m_nShaderIndex, GL_COMPILE_STATUS, &status);
22 if (status!=GL_TRUE)
23 {
24 glGetShaderInfoLog(m_nShaderIndex, 512, NULL, m_StatusBuffer);
25 return false;
26 }
27 else
28 {
29 return true;
30 }
31}
Thanks... Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard) |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Does casting work? A const** to GLchar just means you cant change the GLchars in the array. const ** GLChar psource = (const ** GLCchar)&source; One thing to ask is do you need to make it a 2d array? Right now you just have an array, or a 2d array with one row. What does the shader expect? My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Ariesnl
Member #2,902
November 2002
|
1const GLchar* vertexSource =
2 "#version 150 core\n "
3 "in vec2 position; "
4 "in vec3 ColorIn; "
5 "out vec3 ColorFragment; "
6 "void main()"
7 "{"
8 "ColorFragment = ColorIn;"
9 "gl_Position = vec4(position, 0.0, 1.0);"
10 "}";
This code compiles on the graphics card so I think I need a 2D array... Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard) |
Edgar Reynaldo
Major Reynaldo
May 2007
|
It doesn't just expect a concatenated string? A single one? My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Arthur Kalliokoski
Second in Command
February 2005
|
It compiles to one long string. 00001c60 69 6e 67 00 25 73 00 00 23 76 65 72 73 69 6f 6e |ing.%s..#version| 00001c70 20 31 35 30 20 63 6f 72 65 0a 20 69 6e 20 76 65 | 150 core. in ve| 00001c80 63 32 20 70 6f 73 69 74 69 6f 6e 3b 20 69 6e 20 |c2 position; in | 00001c90 76 65 63 33 20 43 6f 6c 6f 72 49 6e 3b 20 6f 75 |vec3 ColorIn; ou| 00001ca0 74 20 76 65 63 33 20 43 6f 6c 6f 72 46 72 61 67 |t vec3 ColorFrag| 00001cb0 6d 65 6e 74 3b 20 76 6f 69 64 20 6d 61 69 6e 28 |ment; void main(| 00001cc0 29 7b 43 6f 6c 6f 72 46 72 61 67 6d 65 6e 74 20 |){ColorFragment | 00001cd0 3d 20 43 6f 6c 6f 72 49 6e 3b 67 6c 5f 50 6f 73 |= ColorIn;gl_Pos| 00001ce0 69 74 69 6f 6e 20 3d 20 76 65 63 34 28 70 6f 73 |ition = vec4(pos| 00001cf0 69 74 69 6f 6e 2c 20 30 2e 30 2c 20 31 2e 30 29 |ition, 0.0, 1.0)| 00001d00 3b 7d 00 00 00 00 00 00 00 00 50 c1 00 00 c0 3f |;}........P....?|
They all watch too much MSNBC... they get ideas. |
Thomas Fjellstrom
Member #476
June 2000
|
Multiple literal strings that are one after the other get concatenated. -- |
Edgar Reynaldo
Major Reynaldo
May 2007
|
yeah, that's kind of what I meant My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Arvidsson
Member #4,603
May 2004
|
If you want to use a std::string: http://stackoverflow.com/questions/6047527/how-to-convert-stdstring-to-const-char
|
bamccaig
Member #7,536
July 2006
|
So basically it wants a pointer to a string? &source should be your "C string" (that is, a pointer to the beginning of the array of characters) so you may need to store that somewhere in order to take the address of that? const GLchar * str = &source; const GLchar ** ptr = &str; // Here, eat ^ that and leave us alone!
Append: That said, a non-const pointer to a string suggests that they may wish to change it on you, which may or may not throw you for a loop... Do make sure that what you're trying is safe. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
|