void handleCollisions() { // Handle collisions. // -- Check if the helicopter collides with the ground terrain // Calculate the inverse camera matrix GLdouble invCameraMatrix[16]; inverse(getCameraMatrix(), invCameraMatrix); // Get the helicopter position (in camera coordinates) GLdouble heliCameraVec[4] = { helicopterCameraPosX, helicopterCameraPosY, helicopterCameraPosZ, 1 }; // The vector to hold the world position of the helicopter GLdouble heliWorldVec[4]; int index, multindex; // Get the new helicopter position in the world using the inverse camera matrix // and the helicopter position (in camera coordinates) for(index = 0; index < 4; index++) { for(multindex = 0; multindex < 4; multindex++) { heliWorldVec[index] += invCameraMatrix[(4*multindex)+index] * heliCameraVec[multindex]; } } // Get the height of the helicopter GLfloat chopperH = getHeight(heliWorldVec[0], heliWorldVec[2]); // Check for collision with ground if(heliWorldVec[1] <= chopperH || chopperH == -1) { printf("THE HELICOPTER CRASHED! THE APP TOO LOL :O\n"); exitGame(); } }
void display() { // This function is called whenever it is time to render // a new frame; due to the idle()-function below, this // function will get called several times per second // Clear framebuffer & zbuffer glClearColor(0.3, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Set current material glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuseColor); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specularColor); // Place camera and light glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(100,50,50, 0, 0, 0, 0, 1, 0); // No manual control but better place from the start glLoadMatrixd(getCameraMatrix()); glLightfv(GL_LIGHT0, GL_POSITION, light_position); // After camera matrix - camera independent! // Render the scene! renderGround(); renderTerrain(); // Swap front- and backbuffers glutSwapBuffers(); }
/** * Initializes all storages, gathers the camera matrix and calculates the texture dimensions * @param width_in The width of each frame image * @param height_in The height of each frame image * @param x_in The number of voxels in x direction * @param y_in The number of voxels in y direction * @param z_in The number of voxels in z direction */ Reconstruction::Reconstruction(int width_in, int height_in, int x_in, int y_in, int z_in) : x(x_in), y(y_in), z(z_in), imgWidth(width_in), imgHeight(height_in) { // Allocate the boolean storage for the voxels voxels = new bool[x * y * z]; memset(voxels, (unsigned char)255, x*y*z*sizeof(bool)); // Calculate how to distribute the texels on the texture calculateSizes(); // Allocate the image to store the voxels on voxe = cvCreateImage(cvSize(width, height) , IPL_DEPTH_8U, 4); memset(voxe->imageData, (uchar) 255, width*height*4*sizeof(uchar)); // Get the camera matrix for correct reconstruction getCameraMatrix(); LOG("Initialized the reconstruction"); }
void Viewer::drawSphere(const QMatrix4x4& transform, bool picking) { auto r = sceneRoot->get_transform() * puppetRotation * sceneRoot->get_inverse(); auto modelMatrix = puppetPosition * r * transform; auto vp = getCameraMatrix(); auto mvMatrix = mTransformMatrix * modelMatrix; mSphereBufferObject.bind(); sphereShaders.setAttributeBuffer("vert", GL_FLOAT, 0, 3); mSphereNormalBuffer.bind(); sphereShaders.setAttributeBuffer("norm", GL_FLOAT, 0, 3); sphereShaders.setUniformValue(mvpMatrixLoc, vp * modelMatrix); sphereShaders.setUniformValue(mvMatrixLoc, mvMatrix); sphereShaders.setUniformValue(normMatrixLoc, mvMatrix.normalMatrix()); // Whether or not we are picking (to do lighting or not) sphereShaders.setUniformValue(flatLoc, picking); // Light position shouldn't change: always on the eye sphereShaders.setUniformValue(lightPositionLoc, mTransformMatrix * QVector3D()); glDrawArrays(GL_TRIANGLES, 0, numTriangles * 9); }
int main() { GLFWwindow* window; if (!glfwInit()) { printf("Error initializing GLFW\n"); return -1; } glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, GL_VERSION_MAJOR); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, GL_VERSION_MINOR); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); //glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); glfwWindowHint(GLFW_SAMPLES, 8); window = glfwCreateWindow(1920, 1080, "Test Window", glfwGetPrimaryMonitor(), NULL); if (!window) { printf("Error creating GLFW window\n"); glfwTerminate(); return -1; } glfwMakeContextCurrent(window); glfwSetKeyCallback(window, key_callback); glfwSetMouseButtonCallback(window, mouse_button_callback); glfwSetCursorPosCallback(window, cursor_position_callback); glfwSetScrollCallback(window, scroll_callback); if (gl3wInit()) { printf("Error initializing OpenGL\n"); glfwTerminate(); return -1; } printf("OpenGL %s GLSL %s\n", glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION)); if (!gl3wIsSupported(GL_VERSION_MAJOR, GL_VERSION_MINOR)) { printf("OpenGL %i.%i is not supported\n", GL_VERSION_MAJOR, GL_VERSION_MINOR); glfwTerminate(); return -1; } glViewport(0, 0, 1920, 1080); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); GLuint programID = loadShadersvf("shaders/simple.vsh", "shaders/simple.fsh"); GLuint vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); GLuint vbo; glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); //glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_buffer_data), vertex_buffer_data, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, sizeof(sphere_model), sphere_model, GL_STATIC_DRAW); GLuint ibo; glGenBuffers(1, &ibo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(sphere_indices), sphere_indices, GL_STATIC_DRAW); //glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(index_buffer_data), index_buffer_data, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glDisableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); double timesteps[] = {1, 60, 60 * 60, 60 * 60 * 24, 60 * 60 * 24 * 7, 60 * 60 * 24 * 30, 60 * 60 * 24 * 365}; int timestepCounter = 0; World world; world.num_functions = 0; //Add the functions for gravitational attraction to the world's object list, and have it execute when updateWorld() is called addFunction(&world, attract, COMPONENT_POSITION | COMPONENT_VELOCITY); addFunction(&world, move, COMPONENT_POSITION | COMPONENT_VELOCITY); unsigned int bodies[11]; //Create all the planets with the correct masses, sizes, and velocities bodies[0] = createStar(&world, "Sun", 0, 0, 0, 0, 0, 0, 1.989 * pow(10, 30), 6.963 * pow(10,8), 1); bodies[1] = createPlanet(&world, "Mercury", -0.35790 * AU, -0.04240 * AU, -0.11618 * AU, -0.00000004 * AU, 0.00000003 * AU, 0.00000031 * AU, 3.285 * pow(10,23), 2.44 * pow(10,6), 0.4549, 0.4509, 0.4705); bodies[2] = createPlanet(&world, "Venus", -0.46075 * AU, -0.03422 * AU, -0.56289 * AU, -0.00000017 * AU, -0.00000001 * AU, 0.00000014 * AU, 4.867 * pow(10, 24), 6.052 * pow(10,6), 0.4627, 0.568, 0.380); bodies[3] = createPlanet(&world, "Earth", 0.99542 * AU, 0, 0.01938 * AU, 0.00000001 * AU, 0, -0.00000019 * AU, 5.972 * pow(10, 24), 6.371 * pow(10,6), 0, 0.4, 0.6); bodies[4] = createPlanet(&world, "Moon", 0.99708 * AU, -0.00016 * AU, 0.02141 * AU, 0.00000001 * AU + 722.66, 0, -0.00000019 * AU - 722.66, 7.348 * pow(10, 22), 1.737 * pow(10,6), 0.4, 0.4, 0.4); bodies[5] = createPlanet(&world, "Mars", 1.38763 * AU, 0.01755 * AU, -0.79510 * AU, -0.00000009 * AU, -0.00000001 * AU, -0.00000013 * AU, 6.39 * pow(10, 23), 3.39 * pow(10,6), 0.8157, 0.5294, 0.3922); bodies[6] = createPlanet(&world, "Jupiter", 5.32462 * AU, 0.11488 * AU, 1.04223 * AU, 0.00000002 * AU, 0, -0.00000008 * AU, 1.898 * pow(10,27), 69.911 * pow(10,6), 0.8824, 0.7961, 0.7412); bodies[7] = createPlanet(&world, "Saturn", 3.30063 * AU, 0.29595 * AU, -9.47771 * AU, -0.00000006 * AU, 0, -0.00000002 * AU, 5.683 * pow(10,26), 58.232 * pow(10,6), 0.7843, 0.6392, 0.4314); bodies[8] = createPlanet(&world, "Uranus", -18.76415 * AU, -0.21783 * AU, 6.83528 * AU, 0.00000002 * AU, 0, 0.00000004 * AU, 8.681 * pow(10,25), 25.362 * pow(10,6), 0.8314, 0.9804, 0.9922); bodies[9] = createPlanet(&world, "Neptune", -28.07048 * AU, -0.42924 * AU, -10.42730 * AU, -0.00000002 * AU, 0, 0.0000003 * AU, 1.024 * pow(10,26), 24.622 * pow(10,6), 0.2, 0.2902, 0.7451); bodies[10] = createPlanet(&world, "Pluto", -8.88081 * AU, 0.86973 * AU, -31.76914 * AU, -0.00000003 * AU, -0.00000001 * AU, 0.0000001 / 41.0 * AU, 1.309 * pow(10,22), 1.186 * pow(10, 6), 0.7137, 0.6824, 0.6314); double mat4d_projection[4][4] = MATRIX_IDENTITY_4; mat4dProjection(M_PI / 2.0, 16.0/9.0, pow(10,6), pow(10,13), mat4d_projection); unsigned int parent = 3; Camera camera; makeCamera(&camera, 0, 0, pow(10, 9), &world, bodies[parent]); double mat4d_camera[4][4] = MATRIX_IDENTITY_4; float mat4_camera[4][4]; double sensitivity = 0.005; printf("Starting main loop\n"); while (!glfwWindowShouldClose(window)) { clearInput(); glfwPollEvents(); //rotate or zoom out the camera depending on camera movement and scrolling double dx, dy, dz; getMouseDelta(&dx, &dy, &dz); updateCamera(&camera, dx * sensitivity, dy * sensitivity, dz); if (getClicked()) { if(++parent > 10) parent = 0; changeCameraParent(&camera, pow(10, 9), &world, bodies[parent]); } timestepCounter += getTimeStepChange(); if (timestepCounter > 6) timestepCounter = 0; else if (timestepCounter < 0) timestepCounter = 6; setTimeStep(timesteps[timestepCounter]); //get the time since the last frame to do proper delta-timing for the gravitational attraction and movement double delta = timeTick(); updateWorld(&world, delta); getCameraMatrix(&camera, mat4d_camera); double modelView[4][4]; mat4dMlt(mat4d_projection, mat4d_camera, modelView); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(programID); glBindVertexArray(vao); glEnableVertexAttribArray(0); //For each of the objects in the world, loop through them and render them if they have a position and radius, //rendering works by rendering the same sphere over and over, with a different translation and scale //because all objects in this program are spheres for (int i = 0; i < WORLD_MAX_ENTITIES; ++i) { if (isEntity(&world, i, COMPONENT_POSITION | COMPONENT_RADIUS)) { /*double pos[4] = {world.position[i].position[0], world.position[i].position[1], world.position[i].position[2], 1}; vec4dMltMat(mat4d_camera, pos, pos); double distance = vec3dLength(pos); printf("%i: %f\n", i, distance); double mat4d_model[4][4] = MATRIX_IDENTITY_4; double radius = world.radius[i].radius; double scaleFactor = distance * (1 / pow(radius,2)); printf("Scale factor: %f\n", scaleFactor); if (scaleFactor > pow(10,-3)) { printf("Has been scaled\n"); radius = radius / scaleFactor; } printf("Radius: %f\n", radius);*/ double mat4d_model[4][4] = MATRIX_IDENTITY_4; double radius = world.radius[i].radius; double scale[3] = {radius, radius, radius}; mat4dGenScale(scale, mat4d_model); mat4dTranslate(world.position[i].position, mat4d_model); double modelViewProjection[4][4]; mat4dMlt(modelView, mat4d_model, modelViewProjection); float modelViewProjectionf[4][4]; doubleToSingle(modelViewProjection[0], modelViewProjectionf[0], 16); double color[3] = {1,1,1}; if (isEntity(&world, i, COMPONENT_COLOR)) { vec3dSetEqual(world.color[i].color, color); } float colorf[3]; doubleToSingle(color, colorf, 3); GLint colorLoc = glGetUniformLocation(programID, "in_color"); glUniform3fv(colorLoc, 1, colorf); GLint mvpLoc = glGetUniformLocation(programID, "mvp"); glUniformMatrix4fv(mvpLoc, 1, GL_FALSE, modelViewProjectionf[0]); glDrawElements(GL_TRIANGLES, sphere_num_indices, GL_UNSIGNED_INT, 0); } } glDisableVertexAttribArray(0); glBindVertexArray(0); glfwSwapBuffers(window); } glfwDestroyWindow(window); glfwTerminate(); return 0; }
void display() { // This function is called whenever it is time to render // a new frame; due to the idle()-function below, this // function will get called several times per second // Clear framebuffer & zbuffer glClearColor(0.3, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Position light 0 glMatrixMode(GL_MODELVIEW); glLoadIdentity(); GLfloat light_position[] = { 0.0, 0.0, 1.0, 0.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light_position); // Enable lighting and light 0 //glEnable(GL_LIGHTING); //glEnable(GL_LIGHT0); //glEnable(GL_NORMALIZE); // Set default material properties GLfloat mat_shininess[] = { 50.0 }; GLfloat mat_diffuseColor[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_specularColor[] = { 1.0, 1.0, 1.0, 1.0 }; glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuseColor); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specularColor); // Setup projection matrix glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(90, 1, 0.01, 100); // Setup object matrix glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLoadMatrixd(getCameraMatrix()); // Enable Z-buffering glEnable(GL_DEPTH_TEST); // Enable Gouraud shading glShadeModel(GL_SMOOTH); // Enable backface culling glEnable(GL_CULL_FACE); glCullFace(GL_BACK); // Enable texturing //glEnable(GL_TEXTURE_2D); //glBindTexture(GL_TEXTURE_2D, textureId); // // Draw cube using array-based API int to_draw; float spin_speed = 90; for (to_draw = 1; to_draw < 4; to_draw++) { glColor3f(0.8, 0+to_draw*0.2, 0); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glVertexPointer(3, GL_FLOAT, 0, windmill[to_draw]->vertexArray); glNormalPointer(GL_FLOAT, 0, windmill[to_draw]->normalArray); glDrawElements(GL_TRIANGLES, windmill[to_draw]->numIndices, GL_UNSIGNED_INT, windmill[to_draw]->indexArray); } glTranslatef(4.6, 9.15, 0); glRotatef(getElapsedTime()*spin_speed, 1, 0, 0); glPushMatrix(); glColor3f(0.8, 0, 0.4); glRotatef(0, 1, 0, 0); //glRotatef(0, 1, 0, to_draw * 90); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glVertexPointer(3, GL_FLOAT, 0, windmill[0]->vertexArray); glNormalPointer(GL_FLOAT, 0, windmill[0]->normalArray); glDrawElements(GL_TRIANGLES, windmill[0]->numIndices, GL_UNSIGNED_INT, windmill[0]->indexArray); glPopMatrix(); glPushMatrix(); glColor3f(0.8, 0, 0.4); glRotatef(90, 1, 0, 0); //glRotatef(0, 1, 0, to_draw * 90); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glVertexPointer(3, GL_FLOAT, 0, windmill[0]->vertexArray); glNormalPointer(GL_FLOAT, 0, windmill[0]->normalArray); glDrawElements(GL_TRIANGLES, windmill[0]->numIndices, GL_UNSIGNED_INT, windmill[0]->indexArray); glPopMatrix(); glPushMatrix(); glColor3f(0.8, 0, 0.4); glRotatef(180, 1, 0, 0); //glRotatef(0, 1, 0, to_draw * 90); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glVertexPointer(3, GL_FLOAT, 0, windmill[0]->vertexArray); glNormalPointer(GL_FLOAT, 0, windmill[0]->normalArray); glDrawElements(GL_TRIANGLES, windmill[0]->numIndices, GL_UNSIGNED_INT, windmill[0]->indexArray); glPopMatrix(); glPushMatrix(); glColor3f(0.8, 0, 0.4); glRotatef(270, 1, 0, 0); //glRotatef(0, 1, 0, to_draw * 90); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glVertexPointer(3, GL_FLOAT, 0, windmill[0]->vertexArray); glNormalPointer(GL_FLOAT, 0, windmill[0]->normalArray); glDrawElements(GL_TRIANGLES, windmill[0]->numIndices, GL_UNSIGNED_INT, windmill[0]->indexArray); glPopMatrix(); // Swap front- and backbuffers glutSwapBuffers(); }
void drawSkybox() { glPushMatrix(); GLdouble lol[16]; int i = 0; for(i = 0; i<16; i++) { lol[i]= getCameraMatrix()[i]; } lol[12] = 0; lol[13] = 0; lol[14] = 0; glLoadMatrixd(lol); glDisable(GL_DEPTH_TEST); float hf = 50; glBindTexture(GL_TEXTURE_2D, ss[4]); glBegin(GL_POLYGON); glColor3f(1, 1, 1); //baksida glNormal3f(0,0,1); glTexCoord2f(0, 0); glVertex3f(-hf, hf, -hf); glTexCoord2f(0, 1); glVertex3f(-hf,-hf, -hf); glTexCoord2f(1, 1); //glTexCoord2f(getElapsedTime(), 1); glVertex3f(hf,-hf, -hf); glTexCoord2f(1, 0); //glTexCoord2f(getElapsedTime(), 0); glVertex3f(hf, hf, -hf); glEnd(); glBindTexture(GL_TEXTURE_2D, ss[1]); glBegin(GL_POLYGON); //BOT glNormal3f(0, 1, 0); glTexCoord2f(0, 0); glVertex3f(-hf, -hf, -hf); glTexCoord2f(0, 1); glVertex3f(-hf, -hf, hf); glTexCoord2f(1, 1); glVertex3f(hf,-hf,hf); glTexCoord2f(1, 0); glVertex3f(hf,-hf,-hf); glEnd(); glBindTexture(GL_TEXTURE_2D, ss[2]); glBegin(GL_POLYGON); //right glNormal3f(-1, 0, 0); glTexCoord2f(0, 0); glVertex3f(hf,hf,-hf); glTexCoord2f(0, 1); glVertex3f(hf,-hf,-hf); glTexCoord2f(1, 1); glVertex3f(hf,-hf,hf); glTexCoord2f(1, 0); glVertex3f(hf,hf,hf); glEnd(); glBindTexture(GL_TEXTURE_2D, ss[3]); glBegin(GL_POLYGON); //left glNormal3f(1, 0, 0); glTexCoord2f(0, 0); glVertex3f(-hf,hf,hf); glTexCoord2f(0, 1); glVertex3f(-hf,-hf,hf); glTexCoord2f(1, 1); glVertex3f(-hf,-hf,-hf); glTexCoord2f(1, 0); glVertex3f(-hf,hf,-hf); glEnd(); glBindTexture(GL_TEXTURE_2D, ss[0]); glBegin(GL_POLYGON); //front glNormal3f(0, 0, -1); glTexCoord2f(0, 0); glVertex3f(hf,hf,hf); glTexCoord2f(0, 1); glVertex3f(hf,-hf,hf); glTexCoord2f(1, 1); glVertex3f(-hf,-hf,hf); glTexCoord2f(1, 0); glVertex3f(-hf,hf,hf); glEnd(); glBindTexture(GL_TEXTURE_2D, ss[5]); glBegin(GL_POLYGON); //top glNormal3f(0, -1, 0); glTexCoord2f(0, 0); glVertex3f(-hf,hf,hf); glTexCoord2f(0, 1); glVertex3f(-hf,hf,-hf); glTexCoord2f(1, 1); glVertex3f(hf,hf,-hf); glTexCoord2f(1, 0); glVertex3f(hf,hf,hf); glEnd(); glEnable(GL_DEPTH_TEST); glPopMatrix(); }
void display() { // This function is called whenever it is time to render // a new frame; due to the idle()-function below, this // function will get called several times per second // Clear framebuffer & zbuffer glClearColor(0.3, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Position light 0 glMatrixMode(GL_MODELVIEW); glLoadIdentity(); GLfloat light_position[] = { 0.0, 0.0, -1.0, 0.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light_position); //glLoadMatrixd(getCameraMatrix()); GLfloat light_position1[] = { -10.0, 10.0, 20.0, 1.0 }; glLightfv(GL_LIGHT1, GL_POSITION, light_position1); GLfloat ambientColor [] = { 0.0, 0.0, 0.0, 0.0 }; GLfloat diffuseColor[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat specularColor[] = { 1.0, 1.0, 1.0, 1.0 }; glLightfv(GL_LIGHT1, GL_AMBIENT, ambientColor); glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseColor); glLightfv(GL_LIGHT1, GL_SPECULAR, specularColor); //Enable lighting and light 0 glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_NORMALIZE); // Set default material properties GLfloat mat_shininess[] = { 50.0 }; GLfloat mat_diffuseColor[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_specularColor[] = { 1.0, 1.0, 1.0, 1.0 }; glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuseColor); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specularColor); // Setup projection matrix glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(90, 1, 0.01, 500); // Setup object matrix glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLoadMatrixd(getCameraMatrix()); // Enable Z-buffering glEnable(GL_DEPTH_TEST); // Enable Gouraud shading glShadeModel(GL_SMOOTH); // Enable texturing glEnable(GL_TEXTURE_2D); // Enable backface culling glEnable(GL_CULL_FACE); glCullFace(GL_BACK); drawSkybox(); // the floooor glBindTexture(GL_TEXTURE_2D, textureId); int more_floor = 200; int mf = more_floor; glBegin(GL_POLYGON); glNormal3f(0,1,0); glTexCoord2f(0, 0); glVertex3f(-mf,0, -mf); glTexCoord2f(0, 1); glVertex3f(-mf,0, mf); glTexCoord2f(1, 1); glVertex3f(mf,0, mf); glTexCoord2f(1,0); glVertex3f(mf, 0, -mf); glEnd(); glDisable(GL_TEXTURE_2D); glPushMatrix(); drawWindmill(); glTranslatef(25,0,0); drawWindmill(); glTranslatef(-50,0,40); drawWindmill(); glPopMatrix(); // Draw cube using array-based API glPushMatrix(); //glRotatef(-56, 0, 0, 1); glTranslatef(0, 10*fabs(sin(3.14*getElapsedTime()))+2.5, 30); glRotatef((360*getElapsedTime()) / 6, 0, 1, 0); glTranslatef(-80, 0, -80); glRotatef(-45, 0, 1, 0); glScalef(5, 5, 5); //glRotatef(0, 1, 0, to_draw * 90); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glVertexPointer(3, GL_FLOAT, 0, bunny->vertexArray); glNormalPointer(GL_FLOAT, 0, bunny->normalArray); glDrawElements(GL_TRIANGLES, bunny->numIndices, GL_UNSIGNED_INT, bunny->indexArray); glPopMatrix(); glPushMatrix(); glTranslatef(50, 0, 75); glRotatef(-56, 1, 1, 0); glScalef(30, 30, 30); //glRotatef(0, 1, 0, to_draw * 90); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glVertexPointer(3, GL_FLOAT, 0, klingoff->vertexArray); glNormalPointer(GL_FLOAT, 0, klingoff->normalArray); glDrawElements(GL_TRIANGLES, klingoff->numIndices, GL_UNSIGNED_INT, klingoff->indexArray); glPopMatrix(); // Swap front- and backbuffers glutSwapBuffers(); }
void FloatingCamera::simulateSelf(GLdouble deltaTime) { double pyrSpd = -5; double pyrRot = 3; Matrix4D newTransform = Matrix4D::createIdentity(); //Create movement vector Vector3f dVec = {0,0,0}; double dYaw = 0.0; double dPitch = 0.0; double dRoll = 0.0; if(mApp->gMoveForward) { dVec.z = -pyrSpd*deltaTime; } else if(mApp->gMoveBackward) { dVec.z = pyrSpd*deltaTime; } if(mApp->gMoveLeft) { dVec.x = -pyrSpd*deltaTime; } else if(mApp->gMoveRight) { dVec.x = pyrSpd*deltaTime; } if(mApp->gMoveUp) { dVec.y = pyrSpd*deltaTime; } else if(mApp->gMoveDown) { dVec.y = -pyrSpd*deltaTime; } if(mApp->gYawLeft) { dYaw = pyrRot*deltaTime; } else if(mApp->gYawRight) { dYaw = -pyrRot*deltaTime; } if(mApp->gPitchUp) { dPitch = pyrRot*deltaTime; } else if(mApp->gPitchDown) { dPitch = -pyrRot*deltaTime; } if(mApp->gRollLeft) { dRoll = pyrRot*deltaTime; } else if(mApp->gRollRight) { dRoll = -pyrRot*deltaTime; } if(mRechargeTime > 0) { mRechargeTime -= deltaTime; } if(mApp->gShoot) { if(mRechargeTime < 0) { //Shoot MatterNodePtr matterNode(new MatterNode(mApp, VP_RENDER_GEOMETRY, mApp->gBulletMaterial, false, mApp->gBulletFile.c_str())); // matterNode->setOffset(0.0f, 0.0f, 0.0f); matterNode->setTransform(getCameraMatrix().inverted()); Vector3f force = mForward * mApp->gBulletForce; matterNode->setInitialForce(force); mApp->getSceneGraph()->getRoot()->addChild(matterNode); mRechargeTime = RECHARGE_TIME; } } yaw(dYaw); pitch(dPitch); roll(dRoll); walk(dVec.z); fly(dVec.y); strafe(dVec.x); }
void GoalDetector::execute() { getGoalPercept().reset(); //if there is no field percept, then, there is also no goal ?! /* if(!theFieldPercept.isValid()) { return; } */ // estimate the horizon Vector2<double> p1(getArtificialHorizon().begin()); Vector2<double> p2(getArtificialHorizon().end()); int heightOfHorizon = (int)((p1.y + p2.y) * 0.5 + 0.5); // image over the horizon if(heightOfHorizon > (int)getImage().cameraInfo.resolutionHeight-10) return; // clamp the scanline p1.y = Math::clamp((int)p1.y, 10, (int)getImage().cameraInfo.resolutionHeight-10); p2.y = Math::clamp((int)p2.y, 10, (int)getImage().cameraInfo.resolutionHeight-10); // calculate the post candidates along of the horizon Candidate candidates[maxNumberOfCandidates]; int numberOfCandidates = scanForCandidates(p1, p2, candidates); // fallback: try to scan along the center of the image if(numberOfCandidates == 0) { Vector2<double> c1(0,getImage().cameraInfo.getOpticalCenterY()); Vector2<double> c2(getImage().cameraInfo.resolutionWidth-1,getImage().cameraInfo.getOpticalCenterY()); numberOfCandidates = scanForCandidates(c1, c2, candidates); }//end if // try once again... if(numberOfCandidates == 0) { Vector2<double> c1(0,getImage().cameraInfo.resolutionHeight/3); Vector2<double> c2(getImage().cameraInfo.resolutionWidth-1,getImage().cameraInfo.resolutionHeight/3); numberOfCandidates = scanForCandidates(c1, c2, candidates); }//end if // estimate the post base points vector<GoalPercept::GoalPost> postvector; estimatePostsByScanlines(candidates, numberOfCandidates, postvector); //estimatePostsByBlobs(candidates, numberOfCandidates, postvector); if(postvector.empty()) return; // sort the posts by height in the image // the first is the biggest GoalPercept::GoalPost post; // only for comparison sort(postvector.begin(), postvector.end(), post); // minimal height (in px) of an accepted goal post int minimalHeightOfAGoalPost = 20; int numberOfPostsFound = 0; // we are searching for two goal posts GoalPercept::GoalPost postOne; GoalPercept::GoalPost postTwo; int distToBottomImage = getImage().cameraInfo.resolutionHeight - max(postOne.basePoint.y, postTwo.basePoint.y) - 1; // look max 5 pixel down Vector2<int> extraBase(0, min(distToBottomImage,5)); // if the longest post is to short if(postvector.begin()->seenHeight < minimalHeightOfAGoalPost) { return; } // index of the first found post unsigned int idxFirst = 0; // search for the first goal post candidate for(idxFirst = 0; idxFirst < postvector.size(); idxFirst++) { if(postvector[idxFirst].seenHeight >= minimalHeightOfAGoalPost) // consider the field percept ONLY if it is valid //&& theFieldPercept.getLargestValidPoly(getCameraMatrix().horizon).isInside(postvector[idxFirst].basePoint + extraBase)) { numberOfPostsFound = 1; break; } }//end for // if a post were found search for the second one if(numberOfPostsFound > 0) { // at least one post was seen postOne = postvector[idxFirst]; idxFirst++; for(unsigned int i = idxFirst; i < postvector.size(); i++) { postTwo = postvector[i]; if( abs(postTwo.basePoint.x - postOne.basePoint.x) > 50 && postTwo.seenHeight > minimalHeightOfAGoalPost && postOne.color == postTwo.color) //&& // posts have the same color // consider the field percept ONLY if it is valid //theFieldPercept.getLargestValidPoly(getCameraMatrix().horizon).isInside(postvector[i].basePoint + extraBase)) { numberOfPostsFound = 2; break; }//end if }//end for }//end if first found if(numberOfPostsFound > 1) { // sort: which one is left or right if(postOne.basePoint.x > postTwo.basePoint.x) { postOne.type = GoalPercept::GoalPost::rightPost; postTwo.type = GoalPercept::GoalPost::leftPost; }else { postOne.type = GoalPercept::GoalPost::leftPost; postTwo.type = GoalPercept::GoalPost::rightPost; } //TODO: handle the case if the projection is not possible // position on the ground is not reliable if the post cannot be projected postOne.positionReliable = CameraGeometry::imagePixelToFieldCoord( getCameraMatrix(), getImage().cameraInfo, postOne.basePoint.x, postOne.basePoint.y, 0.0, postOne.position); //TODO: handle the case if the projection is not possible // position on the ground is not reliable if the post cannot be projected postTwo.positionReliable = CameraGeometry::imagePixelToFieldCoord( getCameraMatrix(), getImage().cameraInfo, postTwo.basePoint.x, postTwo.basePoint.y, 0.0, postTwo.position); //TODO: try to calculate the position by the top of the post // translate by the post radius postOne.position.normalize(postOne.position.abs() + getFieldInfo().goalpostRadius); postTwo.position.normalize(postTwo.position.abs() + getFieldInfo().goalpostRadius); postOne.positionReliable = postOne.positionReliable && checkIfPostReliable(postOne.basePoint); postTwo.positionReliable = postTwo.positionReliable && checkIfPostReliable(postTwo.basePoint); getGoalPercept().add(postOne); getGoalPercept().add(postTwo); } else if(numberOfPostsFound > 0) // only one post found { //TODO: handle the case if the projection is not possible postOne.positionReliable = CameraGeometry::imagePixelToFieldCoord( getCameraMatrix(), getImage().cameraInfo, postOne.basePoint.x, postOne.basePoint.y, 0.0, postOne.position); postOne.positionReliable = postOne.positionReliable && checkIfPostReliable(postOne.basePoint); postOne.type = GoalPercept::GoalPost::unknownPost; getGoalPercept().add(postOne); }//end else /*************************************************/ // calculate the centroid // at least one post was seen // TODO: clean it up (calculation of the centroid) if(getGoalPercept().getNumberOfSeenPosts() > 0) { //Vector2<double> centroid; //double mainAxisAngle = -getMajorAxis( goalColor, centroid); Vector2<double> centroid = getGoalPercept().getPost(0).basePoint - Vector2<double>(0.0, getGoalPercept().getPost(0).seenHeight*0.5); if(getGoalPercept().getNumberOfSeenPosts() > 1) { centroid += getGoalPercept().getPost(1).basePoint - Vector2<double>(0.0, getGoalPercept().getPost(1).seenHeight*0.5); centroid /= 2.0; }//end if Vector2<double> angles = CameraGeometry::angleToPointInImage( getCameraMatrix(), getImage().cameraInfo, (int)centroid.x, (int)centroid.y); getGoalPercept().angleToSeenGoal = angles.x; getGoalPercept().goalCentroid = CameraGeometry::imagePixelToWorld( getCameraMatrix(), getImage().cameraInfo, centroid.x, centroid.y, 3000.0); DEBUG_REQUEST("ImageProcessor:GoalDetector:mark_goal", CIRCLE_PX(ColorClasses::red, (int)centroid.x, (int)centroid.y, 5); );
void renderHelicopter() { // Render the helicopter. // -- Render the helicopter a fix position relative to the camera. // -- Rotate the blades of the main and back rotors. // Copy the cameraMatrix. GLdouble helicopterMatrix[16]; GLdouble* cameraMatrix = getCameraMatrix(); int i; for(i = 0; i < 16; i++) { helicopterMatrix[i] = cameraMatrix[i]; } // Fix position (relative the camera) helicopterMatrix[12] = 0; helicopterMatrix[13] = 0; helicopterMatrix[14] = 0; // Fix rotation (relative the camera) helicopterMatrix[0] = 1; helicopterMatrix[1] = 0; helicopterMatrix[2] = 0; helicopterMatrix[4] = 0; helicopterMatrix[5] = 1; helicopterMatrix[6] = 0; helicopterMatrix[8] = 0; helicopterMatrix[9] = 0; helicopterMatrix[10] = 1; // Load the helicopterMatrix instead of cameraMatrix. glLoadMatrixd(helicopterMatrix); // Move it to its position (relative to the camera) to achieve third person view. glTranslatef(helicopterCameraPosX,helicopterCameraPosY,helicopterCameraPosZ); // The model is off 90 deg, rotate it. glRotatef(-90, 0,1,0); // Make it rather small glScalef(0.35f,0.35f,0.35f); // Render the helicopter glBindTexture(GL_TEXTURE_2D, helicopterTexture); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); GLfloat planeS[] = {1, 0.0, 0.0, 1}; GLfloat planeT[] = {0.0, 1, 0.0, 1}; glTexGenfv(GL_S, GL_OBJECT_PLANE, planeS); glTexGenfv(GL_T, GL_OBJECT_PLANE, planeT); glVertexPointer(3, GL_FLOAT, 0, modelApache->vertexArray); glNormalPointer(GL_FLOAT, 0, modelApache->normalArray); glDrawElements(GL_TRIANGLES, modelApache->numIndices, GL_UNSIGNED_INT, modelApache->indexArray); glBindTexture(GL_TEXTURE_2D, textureRotor); // Draw the main rotor glPushMatrix(); glTranslatef(0.1,4.9,-0.10); glRotatef(1*360*fmod(getElapsedTime(),60),0,1,0); glVertexPointer(3, GL_FLOAT, 0, modelRotor->vertexArray); glNormalPointer(GL_FLOAT, 0, modelRotor->normalArray); glDrawElements(GL_TRIANGLES, modelRotor->numIndices, GL_UNSIGNED_INT, modelRotor->indexArray); glPopMatrix(); // Draw the back rotor glPushMatrix(); glTranslatef(11.7,3.8,1); glRotatef(4*360*fmod(getElapsedTime(),60),0,0,1); glVertexPointer(3, GL_FLOAT, 0, modelBackRotor->vertexArray); glNormalPointer(GL_FLOAT, 0, modelBackRotor->normalArray); glDrawElements(GL_TRIANGLES, modelBackRotor->numIndices, GL_UNSIGNED_INT, modelBackRotor->indexArray); glPopMatrix(); // Load back the cameraMatrix again. glLoadMatrixd(cameraMatrix); }
void renderSkyBox() { // Render the SkyBox. // -- Renders the SkyBox sides and fixes them to the camera position. // Make sure the SkyBox is fixed to the camera GLdouble skyBoxMatrix[16]; GLdouble* cameraMatrix = getCameraMatrix(); int i; for(i = 0; i < 16; i++) { skyBoxMatrix[i] = cameraMatrix[i]; } skyBoxMatrix[12] = 0; skyBoxMatrix[13] = 0; skyBoxMatrix[14] = 0; glLoadMatrixd(skyBoxMatrix); // Draw the skybox polygons glBindTexture(GL_TEXTURE_2D, texturePositiveZ); glBegin(GL_POLYGON); glColor3f(1, 1, 1); glNormal3f(0, 0, 1); glTexCoord2f(0, 0); glVertex3f(-skyBoxSize, skyBoxSize, -skyBoxSize); glTexCoord2f(0, 1); glVertex3f(-skyBoxSize, -skyBoxSize, -skyBoxSize); glTexCoord2f(1, 1); glVertex3f(skyBoxSize, -skyBoxSize, -skyBoxSize); glTexCoord2f(1, 0); glVertex3f(skyBoxSize, skyBoxSize, -skyBoxSize); glEnd(); glBindTexture(GL_TEXTURE_2D, textureNegativeX); glBegin(GL_POLYGON); glColor3f(1, 1, 1); glNormal3f(1, 0, 0); glTexCoord2f(0, 0); glVertex3f(-skyBoxSize, skyBoxSize, skyBoxSize); glTexCoord2f(0, 1); glVertex3f(-skyBoxSize, -skyBoxSize, skyBoxSize); glTexCoord2f(1, 1); glVertex3f(-skyBoxSize, -skyBoxSize, -skyBoxSize); glTexCoord2f(1, 0); glVertex3f(-skyBoxSize, skyBoxSize, -skyBoxSize); glEnd(); glBindTexture(GL_TEXTURE_2D, texturePositiveX); glBegin(GL_POLYGON); glColor3f(1, 1, 1); glNormal3f(-1, 0, 0); glTexCoord2f(0, 0); glVertex3f(skyBoxSize, skyBoxSize, -skyBoxSize); glTexCoord2f(0, 1); glVertex3f(skyBoxSize, -skyBoxSize, -skyBoxSize); glTexCoord2f(1, 1); glVertex3f(skyBoxSize, -skyBoxSize, skyBoxSize); glTexCoord2f(1, 0); glVertex3f(skyBoxSize, skyBoxSize, skyBoxSize); glEnd(); glBindTexture(GL_TEXTURE_2D, textureNegativeZ); glBegin(GL_POLYGON); glColor3f(1, 1, 1); glNormal3f(0, 0, -1); glTexCoord2f(0, 0); glVertex3f(skyBoxSize, skyBoxSize, skyBoxSize); glTexCoord2f(0, 1); glVertex3f(skyBoxSize, -skyBoxSize, skyBoxSize); glTexCoord2f(1, 1); glVertex3f(-skyBoxSize, -skyBoxSize, skyBoxSize); glTexCoord2f(1, 0); glVertex3f(-skyBoxSize, skyBoxSize, skyBoxSize); glEnd(); glBindTexture(GL_TEXTURE_2D, texturePositiveY); glBegin(GL_POLYGON); glColor3f(1, 1, 1); glNormal3f(0, -1, 0); glTexCoord2f(0, 0); glVertex3f(-skyBoxSize, skyBoxSize, skyBoxSize); glTexCoord2f(0, 1 ); glVertex3f(-skyBoxSize, skyBoxSize, -skyBoxSize); glTexCoord2f(1, 1); glVertex3f(skyBoxSize, skyBoxSize,-skyBoxSize); glTexCoord2f(1,0); glVertex3f(skyBoxSize, skyBoxSize, skyBoxSize); glEnd(); glBindTexture(GL_TEXTURE_2D, textureNegativeY); glBegin(GL_POLYGON); glColor3f(1, 1, 1); glNormal3f(0, 1, 0); glTexCoord2f(0, 0); glVertex3f(-skyBoxSize, -skyBoxSize, -skyBoxSize); glTexCoord2f(0, 1); glVertex3f(-skyBoxSize, -skyBoxSize, skyBoxSize); glTexCoord2f(1, 1); glVertex3f(skyBoxSize, -skyBoxSize, skyBoxSize); glTexCoord2f(1, 0); glVertex3f(skyBoxSize, -skyBoxSize, -skyBoxSize); glEnd(); glLoadMatrixd(cameraMatrix); }
void Viewer::paintGL() { //particleSystem.Step(); glClearColor(0.7, 0.7, 0.7, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //std::cerr << "no"; glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glVertexAttribPointer( 0, // attribute 0. No particular reason for 0, but must match the layout in the shader. 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // 2nd attribute buffer : positions of particles' centers glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, particles_position_buffer); glVertexAttribPointer( 1, // attribute. No particular reason for 1, but must match the layout in the shader. 4, // size : x + y + z + size => 4 GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); glEnableVertexAttribArray(2); glBindBuffer(GL_ARRAY_BUFFER, particles_color_buffer); glVertexAttribPointer( 2, // attribute. No particular reason for 1, but must match the layout in the shader. 4, // size : x + y + z + size => 4 GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); GLfloat g_particule_position_size_data[] = { 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.5f, 0.0f, 0.5f, 0.0f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f, 0.0f, 0.5f, -0.5f, 0.5f, 0.0f, 0.5f, -0.5f, -0.5f, 0.0f, 0.5f, 0.5f, 0.0f, 0.0f, 0.5f, 0.5f, 0.5f, 0.0f, 0.5f, 0.5f, -0.5f, 0.0f, 0.5f, }; GLfloat g_particule_color_data[] = { 1.0f, 0.0f, 0.0f }; glBindBuffer(GL_ARRAY_BUFFER, particles_position_buffer); glBufferData(GL_ARRAY_BUFFER, MaxParticles * 4 * sizeof(GLfloat), NULL, GL_STREAM_DRAW); // Buffer orphaning, a common way to improve streaming perf. See above link for details. float particles[ParticlesCount*4]; float colors[ParticlesCount*4]; particleSystem.Draw(particles, colors); glBufferSubData(GL_ARRAY_BUFFER, 0, ParticlesCount * sizeof(GLfloat) * 4, particles); glBindBuffer(GL_ARRAY_BUFFER, particles_color_buffer); glBufferData(GL_ARRAY_BUFFER, MaxParticles * 4 * sizeof(GLfloat), NULL, GL_STREAM_DRAW); // Buffer orphaning, a common way to improve streaming perf. See above link for details. glBufferSubData(GL_ARRAY_BUFFER, 0, ParticlesCount * sizeof(GLfloat) * 4, colors); glVertexAttribDivisor(0, 0); // particles vertices : always reuse the same 4 vertices -> 0 glVertexAttribDivisor(1, 1); // positions : one per quad (its center) -> 1 glVertexAttribDivisor(2, 1); // Draw the triangle ! //glDrawArrays(GL_TRIANGLES, 0, 3); // Starting from vertex 0; 3 vertices total -> 1 triangle glPointSize(3.0); //std::cerr << mvp.constData() << std::endl; glUniformMatrix4fv(mvpMatrix, 1, false, (getCameraMatrix() * modelMatrix).constData()); //glDrawArrays(GL_LINE_LOOP, 0, 40); //glDrawArraysInstanced(GL_LINE_LOOP, 0, 40, ParticlesCount); glDrawArraysInstanced(GL_POINTS, 40, 1, ParticlesCount); //glDrawArrays(GL_TRIANGLE_STRIP, 0, 3); glDisableVertexAttribArray(0); }
/** * This is pretty low performance, but it is used only for debugging physics, so it is good enough */ void GLHelper::drawLine(const glm::vec3 &from, const glm::vec3 &to, const glm::vec3 &fromColor, const glm::vec3 &toColor, bool willTransform) { static GLuint program, viewTransformU, lineInfoU, vao, vbo; static std::map<std::string, Uniform*> uniformMap;//FIXME That map will always be empty, maybe we should overload if (program == 0 || vbo == 0 || vao == 0) { program = initializeProgram("./Data/Shaders/Line/vertex.glsl", "./Data/Shaders/Line/fragment.glsl", uniformMap); lineInfoU = glGetUniformLocation(program, "lineInfo"); viewTransformU = glGetUniformLocation(program, "cameraTransformMatrix"); state->setProgram(program); vbo = generateBuffer(1); glBindBuffer(GL_ARRAY_BUFFER, vbo); std::vector<GLint> indexes; indexes.push_back(0); indexes.push_back(1); glBufferData(GL_ARRAY_BUFFER, indexes.size() * sizeof(GLint), indexes.data(), GL_STATIC_DRAW); //this means the vao is not created yet. glGenVertexArrays(1, &vao); glBindVertexArray(vao); //stride means the space between start of 2 elements. 0 is special, means the space is equal to size. glVertexAttribPointer(0, 1, GL_INT, GL_FALSE, 0, 0); glEnableVertexAttribArray(0); } state->setProgram(program); glm::mat4 matrix(glm::vec4(from, 1.0f), glm::vec4(to, 1.0f), glm::vec4(fromColor, 1.0f), glm::vec4(toColor, 1.0f)); glUniformMatrix4fv(lineInfoU, 1, GL_FALSE, glm::value_ptr(matrix)); if (willTransform) { glUniformMatrix4fv(viewTransformU, 1, GL_FALSE, glm::value_ptr(getProjectionMatrix() * getCameraMatrix())); } else { glUniformMatrix4fv(viewTransformU, 1, GL_FALSE, glm::value_ptr(glm::mat4(1.0))); } glBindVertexArray(vao); glDrawArrays(GL_LINES, 0, 2); glBindVertexArray(0); //state->setProgram(0); checkErrors("drawLine"); }