• Content count

  • Joined

  • Last visited

Community Reputation

134 Neutral

About Kametec

  • Rank
  1. OpenGL OpenGL Rotation issue

    Hi, if I understand properly, you don't really have an issue, you're asking for a know-how, right? I made my cube example recently and I added rotation to it, so I could see a cube instead of a square. Drawing lines along edges (and tinkering with glPolygonOffset so they didn't collide) made it nice looking too. Anyway, here's a description of how I added rotation to my example. I cannot guarantee everything is used properly, it's just how I made it. I did this: I added globally accessible variables to hold rotation angles and directions for each axis, because Glut cannot pass custom arguments to callback functions. I also defined a step value, which was used to increase or decrease the angle based on the direction. I defined rotation matrices in my vertex shader. They can be found here: http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations I made my vertex shader accept three angles as vec3 uniform variable. (All vertices I had defined would be rendered with same rotation, I hope that's correct usage of uniform variable.) I made my vertex shader to multiply the matrices together and with the vertex location. I assume you know what a transformation matrix is or can at least look it up. Now I know it's better for performance to prepare one final transformation matrix (by multiplying transformation matrices for all transformations needed) in your application and pass that final matrix to the shader, so it doesn't have to do more matrix multiplications than necessary. But it was a test project and I didn't want to worry about representing matrices and multiplying them, GLSL provided me with relevant data types and operators. It also provides trigonometric functions. I prepared a key press callback function to use with glutKeyboardFunc, which would set direction for rotations, or clear them. I prepared a timer callback function to use with glutTimerFunc, which would update rotation angles, schedule itself again and if any value got updated, it would flag window for redraw with glutPostRedisplay(). And that's it - at this point I had a cube which I could rotate. Few notes: I kept the angle values in range from 0 to 2*M_PI ,in order to allow the rotation to go on indefinetly. I had to tinker with step and timer values so the rotation would seem smooth. This way works because the cube is centered at origin. If it were somewhere else, it would go in circles, rather than rotate in place.   My aim is to inspire you how to do what you want, I don't want to type the code for you. All the stuff I learned while trying to figure out how to get it working helped me a lot in the long run.   I am willing to help with coding, but in answers to specific questions, this one is too general.
  2. Hi, thanks for your reply, it helped me to solve the problem. The error was caused by missing ifs.close(), and the second shader wasn't read correctly because of it.   As to why I used GLchar **str, well, I'm starting to learn C++ as well as OpenGL. I have some experience with other languages, though. I've read in documentaion that glShaderSource accepts GLchar **, so I declared my variable as GLchar **. Thinking of it as two-dimensional array helped me to get it running.   Now, that I am familiar with & and * operators I admit you're right, and I will use an array of GLchar passed as &arr_name in future code.   In summary: I've included ifs.close() and the whole issue dissapeared. I didn't do anything else, so I managed to get file reading to work properly. Thanks again.
  3. I've included your recommendation into my code. My error still stands unchanged, I think the method of reading source files is not responsible for sure now.
  4. glewInit is called after both window and context are created. EOF character is not read, or at least should not, according to http://www.cplusplus.com/reference/ios/ios/good/
  5.   You have to append new lines only if you're using a reading function, which discards them. Such as std::istream::getline. I am sure I'm passing the file content as is, including line breaks. I believe I would be getting compile errors otherwise.       I've included a function which calls glGetError() and writes the error, together with an info string passed as parameter, to cout. I've got this output: Entering main: invalid operation   Initializing GLchar **str: invalid operation   glutInit: invalid operation   glutInitDisplayMode: invalid operation   glutInitWindowSize: invalid operation   glutInitContextVersion: invalid operation   glutInitContextProfile: invalid operation   glutInitCreateWindow: no error   glewInit: invalid enumerant   glGenVertexArrays: no error   glBindVertexArray: no error   glGenBuffers: no error   glBindBuffer: no error   glBufferData: no error   Opening triangles.vert: no error   Reading triangles.vert: no error   Creating vertex shader: no error   Assigning vertex shader a source: no error   Compiling vertex shader: no error   Checking compile status: no error   Checking info log length: no error   Reinitializing GLchar **str: no error   Opening triangles.frag: no error   Reading triangles.frag: no error   Creating fragment shader: no error   Assigning fragment shader a source: no error   Compiling fragment shader: no error   Checking compile status: no error   Checking info log length: no error   Creating shader program: no error   Attaching vertex shader: no error   Attaching fragment shader: no error   Linking the program: no error   Checking link status: no error   Checking info log length: no error   Getting info log: no error   linker_log: Vertex shader(s) failed to link, fragment shader(s) failed to link. Vertex link error: INVALID OPERATION. ERROR: error(#97) No program main found fragment link error: INVALID OPERATION. ERROR: error(#97) No program main found   Writing info log: no error
  6. No, I haven't tried glGetError() yet, if that's what you meant by your reply. So I've included following code: GLenum errCode; GLchar *errString; errCode = glGetError(); if (errCode != GL_NO_ERROR) {     errString = (GLchar *)gluErrorString(errCode);     cout << errString << endl; } With this result: invalid enumerant
  7. Hi, I'm getting started with OpenGL. I'm trying to get my first program working, but I have no luck so far and I have no idea why. My test program is inspired by the first program in a book named "OpenGL Programming Guide, The Official Guide to Learning OpenGL, Version 4.3, Eight Edition".   I've written both vertex and fragment shaders, I've written code to initialize FreeGlut, GLEW, compile the shaders and link the shader program. But I have issues with the linking proccess. The output of glGetProgramInfoLog is this:   Vertex shader(s) failed to link, fragment shader(s) failed to link. Vertex link error: INVALID_OPERATION. ERROR: error(#97) No program main found fragment link error: INVALID_OPERATION. ERROR: error(#97) No program main found   I've written definition of my shaders into files, their contents are: Vertex shader in triangles.vert:   #version 400 core layout(location = 0) in vec4 vPosition; void main() {     gl_Position = vPosition; }   Fragment shader in triangles.frag:   #version 400 core out vec4 fColor; void main() {     fColor = vec4(0.0, 0.0, 1.0, 1.0); }   I believe that the error suggests that there is something wrong with my shaders, but I don't know what. Both have void main() present.   For completeness' sake I include my C++ program which takes care about compiling and linking the shaders:   int main(int argc, char** argv) {     GLuint vShad,fShad,prg;     GLchar **str = new GLchar*[1];     GLubyte i;     GLchar c;     GLint err;     str[0] = new GLchar[256];     for (i=0; i<255;i++)         str[0][i] = NULL;     str[0][255] = NULL;     i = 0;     glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA); glutInitWindowSize(512,512); glutInitContextVersion(4,0); glutInitContextProfile(GLUT_CORE_PROFILE); glutCreateWindow(argv[0]);     if (glewInit())         return -1;     //Code omitted: vertices and buffers      //vertex shader     std::ifstream ifs("F:\\dev\\project\\test\\test\\triangles.vert");     while (ifs.get(c)) //Reading contents of the file into GLchar**     {         str[0][i] = c;         i++;     }     vShad = glCreateShader(GL_VERTEX_SHADER);     glShaderSource(vShad,1,(const char **)str,NULL);     glCompileShader(vShad);     glGetShaderiv(vShad,GL_COMPILE_STATUS,&err);     if (err == GL_FALSE)     {         //Code omitted: Fetching compiler log         return 1;     }     //fragment shader     for (i=0; i<255;i++)         str[0][i] = NULL;     str[0][255] = NULL;     i = 0;     ifs.open("F:\\dev\\project\\test\\test\\triangles.frag");     while (ifs.get(c)) //Reading contents of the file into GLchar**     {         str[0][i] = c;         i++;     }     fShad = glCreateShader(GL_FRAGMENT_SHADER);     glShaderSource(fShad,1,(const char **)str,NULL);     glCompileShader(fShad);     glGetShaderiv(fShad,GL_COMPILE_STATUS,&err);     if (err == GL_FALSE)     {         //Code omitted: Fetching compiler log         return 2;     }     //shader program     prg = glCreateProgram();     glAttachShader(prg,vShad);     glAttachShader(prg,fShad);     glLinkProgram(prg);     glGetProgramiv(prg,GL_LINK_STATUS,&err);     if (err == GL_FALSE)     {         //Code omitted: Fetching linker log         return 3;     }     glUseProgram(prg);     //Code omitted     return 0; }   A few notes: I had to reduce #version 430 core to #version 400 core, because FreeGlut couldn't initialize OpenGL 4.3 context on my hardware. I am sure that shaders are compiled successfully. My main() returns 3, indicating an error with linking. I have omitted code which I believe to be irrelevant to my issue. Both FreeGlut and GLEW are initialized. I'm using MS Visual Studio 2010 Express, FreeGlut 2.8.1 and GLEW 1.9.0.   I would be really grateful for any advice on where should I check for error and what kind of error might that be. Thanks in advance.   edit: Code omitted comments are now in right places. edit2: Glut window, profile and context initialization code included, unnecessary empty lines in code removed edit3: Code responsible for reading files updated