GLSphereYellow::GLSphereYellow(float center_x, float center_y, float center_z, float radius, int rows, int segments ) { _center.x() = center_x; _center.y() = center_y; _center.z() = center_z; _radius = radius; _rows = rows; _segments = segments; _render_normal_vectors = false; _program_normals = -1; _program = -1; initShader(); initVBO(); initShaderNormal(); initVBONormals(); }
GLSphereDirect::GLSphereDirect(float center_x, float center_y, float center_z, float radius, int rows, int segments ) { _center.x() = center_x; _center.y() = center_y; _center.z() = center_z; _radius = radius; _rows = rows; _segments = segments; _render_normal_vectors = false; initShader(); initVBO(); initShaderNormal(); initVBONormals(); }
GLBeerPint::GLBeerPint(float center_x, float center_y, float center_z, float radius, float length, int rows, int segments ) { _center.x() = center_x; _center.y() = center_y; _center.z() = center_z; _radius = radius; _length = length; _rows = rows; _segments = segments; _render_normal_vectors = false; _program_normals = -1; _program = -1; initShader(); initVBO(); initShaderNormal(); initVBONormals(); }
/** * Constructeur de Mesh. * * @param verticesSelectionnes * @param mesh */ Mesh::Mesh(std::vector<int> verticesSelectionnes, Mesh *mesh):nbTriangles_(0), nbVertices_(0), verticesBuffer_(QGLBuffer::VertexBuffer), normalesBuffer_(QGLBuffer::VertexBuffer), /*couleursBuffer_(QGLBuffer::VertexBuffer), */ indicesBuffer_(QGLBuffer::IndexBuffer), centre_(), shaderType_(PHONG), programmeShader_(), couleur_(200, 150, 120), octree_(0), affichageOctree_(false), matTransform_(), matTransformArray_(), estSelectionne_(false), estEditable_(true) { majTransformation(); octree_=new Octree(); std::vector<Vertex> &vertices=mesh->getVertices(); std::vector<Triangle> &triangles=mesh->getTriangles(); std::vector<int> trianglesSelectionnes=mesh->getTrianglesAPartirDeVertices( verticesSelectionnes); nbTriangles_=trianglesSelectionnes.size(); Vertex v1, v2, v3; int iVer1, iVer2, iVer3; std::set<Vertex> setVertices; for (int i=0; i<nbTriangles_; i++) { v1=Vertex(vertices[triangles[trianglesSelectionnes[i]].getIndiceVertex(1)], setVertices.size()); iVer1=rajouterVertexSansDoublons(v1, i, setVertices); v2=Vertex(vertices[triangles[trianglesSelectionnes[i]].getIndiceVertex(2)], setVertices.size()); iVer2=rajouterVertexSansDoublons(v2, i, setVertices); v3=Vertex(vertices[triangles[trianglesSelectionnes[i]].getIndiceVertex(3)], setVertices.size()); iVer3=rajouterVertexSansDoublons(v3, i, setVertices); triangles_.push_back(Triangle(triangles[trianglesSelectionnes[i]].getNormale(), iVer1, iVer2, iVer3, i)); } nbVertices_=vertices_.size(); deplacerEn(QVector3D(0, 0, 0)); initDistanceVertexMaxEtCentreMeshEtOctree(); initVBO(); }
GLSphereDirect::GLSphereDirect(float center_x, float center_y, float center_z, float radius, int rows, int segments, glm::vec3 matl_ambient_color, int lightSourceOption) { _center.x() = center_x; _center.y() = center_y; _center.z() = center_z; _radius = radius; _rows = rows; _segments = segments; _render_normal_vectors = false; _material._ambient_material = matl_ambient_color; _lightSourceOption = lightSourceOption; initShader(); initVBO(); initShaderNormal(); initVBONormals(); }
void Graphics_init() { glfwInit(); glfwOpenWindow(WIDTH, HEIGHT, 0, 0, 0, 0, 0, 0, GLFW_WINDOW); glfwSetWindowCloseCallback(&closeWindowCallBack, NULL); glDisable(GL_CULL_FACE); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // 4-byte pixel alignment glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,WIDTH,HEIGHT,0,-1, 1); glMatrixMode(GL_MODELVIEW); //glLoadIdentity(); glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glClearColor(0,0,0,1); glClear(GL_COLOR_BUFFER_BIT); printGLError(); initVBO(); printGLError(); glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D,texture); glfwLoadTexture2D("ball.tga", GLFW_BUILD_MIPMAPS_BIT); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glEnable( GL_TEXTURE_2D ); printGLError(); }
/// // main() for GLinterop example // int main(int argc, char** argv) { cl_device_id device = 0; imWidth = 256; imHeight = 256; vbolen = imHeight; initGlut(argc, argv, imWidth, imHeight); vbo = initVBO(vbolen); initTexture(imWidth, imHeight); // Create an OpenCL context on first available platform context = CreateContext(); if (context == NULL) { std::cerr << "Failed to create OpenCL context." << std::endl; return 1; } // Create a command-queue on the first device available // on the created context commandQueue = CreateCommandQueue(context, &device); if (commandQueue == NULL) { Cleanup(); return 1; } // Create OpenCL program from GLinterop.cl kernel source program = CreateProgram(context, device, "kernel/GLinterop.cl"); if (program == NULL) { Cleanup(); return 1; } // Create OpenCL kernel kernel = clCreateKernel(program, "init_vbo_kernel", NULL); if (kernel == NULL) { std::cerr << "Failed to create kernel" << std::endl; Cleanup(); return 1; } tex_kernel = clCreateKernel(program, "init_texture_kernel", NULL); if (tex_kernel == NULL) { std::cerr << "Failed to create kernel" << std::endl; Cleanup(); return 1; } // Create memory objects that will be used as arguments to // kernel if (!CreateMemObjects(context, tex, vbo, &cl_vbo_mem, &cl_tex_mem)) { Cleanup(); return 1; } // Perform some queries to get information about the OpenGL objects performQueries(); glutMainLoop(); std::cout << std::endl; std::cout << "Executed program succesfully." << std::endl; Cleanup(); return 0; }
void Model::makegeo(float r, float g, float b) { //takes the rgb value to color the model with when drawn if(_vboInit) { //vbo initilsations initVBO(); _vboInit = false; } if(!_hasNor && !_hasTex) { //no normals or uvs so draw the vertices from vbo glBindBuffer(GL_ARRAY_BUFFER, verBuff); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(fVector3d), 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuff); glColor3f(r,g,b); glDrawElements(GL_TRIANGLES, _vboInd.size(), GL_UNSIGNED_INT, 0); glDisableClientState(GL_VERTEX_ARRAY); } else if(_hasNor && !_hasTex) { //no uvs so draw the vertices and the normals from the vbo glBindBuffer(GL_ARRAY_BUFFER, verBuff); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(fVector3d), 0); glBindBuffer(GL_ARRAY_BUFFER, norBuff); glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, sizeof(fVector3d), 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuff); glColor3f(r,g,b); glDrawElements(GL_TRIANGLES, _vboInd.size(), GL_UNSIGNED_INT, 0); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); } else if(!_hasNor && _hasTex) { //no normals so draw the vertices and the uvs from the vbo glBindBuffer(GL_ARRAY_BUFFER, verBuff); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(fVector3d), 0); glBindBuffer(GL_ARRAY_BUFFER, texBuff); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(fTexCoords3d), 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuff); glColor3f(r,g,b); glDrawElements(GL_TRIANGLES, _vboInd.size(), GL_UNSIGNED_INT, 0); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } else if(_hasNor && _hasTex) { //draw the vertices and the normals and the uvs from the vbo glBindBuffer(GL_ARRAY_BUFFER, verBuff); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(fVector3d), 0); glBindBuffer(GL_ARRAY_BUFFER, norBuff); glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, sizeof(fVector3d), 0); glBindBuffer(GL_ARRAY_BUFFER, texBuff); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(fTexCoords3d), 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuff); glColor3f(r,g,b); glDrawElements(GL_TRIANGLES, _vboInd.size(), GL_UNSIGNED_INT, 0); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } }
bool LTexture::loadTextureFromPixels32() { //Loading flag bool success = true; //There is loaded pixels if( mTextureID == 0 && mPixels32 != NULL ) { //Generate texture ID glGenTextures( 1, &mTextureID ); //Bind texture ID glBindTexture( GL_TEXTURE_2D, mTextureID ); //Generate texture glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, mTextureWidth, mTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, mPixels32 ); //Set texture parameters glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, DEFAULT_TEXTURE_WRAP ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, DEFAULT_TEXTURE_WRAP ); //Unbind texture glBindTexture( GL_TEXTURE_2D, NULL ); //Check for error GLenum error = glGetError(); if( error != GL_NO_ERROR ) { printf( "Error loading texture from %p pixels! %s\n", mPixels32, gluErrorString( error ) ); success = false; } else { //Release pixels delete[] mPixels32; mPixels32 = NULL; //Generate VBO initVBO(); //Set pixel format mPixelFormat = GL_RGBA; } } //Error else { printf( "Cannot load texture from current pixels! " ); //Texture already exists if( mTextureID != 0 ) { printf( "A texture is already loaded!\n" ); } //No pixel loaded else if( mPixels32 == NULL ) { printf( "No pixels to create texture from!\n" ); } success = false; } return success; }
/** * Inverse toutes les normales des triangles. * */ void Mesh::inverserNormales() { for (int i=0;i<nbTriangles_;i++) triangles_[i].inverserNormale(); initVBO(); }
void Tetrahedron::initializeContextSpecificVars(int threadId) { GPUCylinderOffset = 50; // had it at 25 before initVBO(threadId); initGL(); }
Splatterer::Splatterer( const Logger* logger, const Context* context, GLfloat viewportSize, QString textureFilename, BufferTexture* baseDiscomfort) : pointBuffer(0), screenSizedQuadBuffer(0), framebufferObject(0), densityDiscomfortVelocity(NULL), splatAreas(NULL), agent(NULL), splatAttribVertex(-1), splatProgram(NULL), splatVertexShader(NULL), splatGeometryShader(NULL), splatFragmentShader(NULL), camera(NULL), bufferSideLength(viewportSize), totalBufferSize(0), densityDiscomfortVelocityTripple(NULL), logger(logger), context(context), prepareFramebufferRenderer(NULL), discomfortProgram(NULL), discomfortVertexShader(NULL), discomfortGeometryShader(NULL), discomfortFragmentShader(NULL), discomfortFactor(NULL), discomfortRadius(NULL), discomfortPosition(NULL) { attachments[0] = GL_COLOR_ATTACHMENT0; attachments[1] = GL_COLOR_ATTACHMENT1; initCamera(); initSplatShaderProgram(); initAttribs(); initVBO(); initUniforms(); initFramebufferObject(); try { // // Create splatted texture // QImage image = Texture::loadTexture(textureFilename, false, true); uint pixelCount = image.width() * image.height(); std::vector<float> data(pixelCount * 4); Texture::convertToFloats(image, data, pixelCount); glActiveTexture(GL_TEXTURE0); agent = new Texture2D(image.width(), image.height(), GL_CLAMP_TO_EDGE, GL_LINEAR, GL_LINEAR, GL_RGBA32F, GL_RGBA, GL_FLOAT, &data[0]); totalBufferSize += image.width() * image.height() * 4 * 4; } catch (Exception& e) { throw Exception("Could not load splatting texture: " + e.message); } // // Create buffer object for density, discomfort and velocity // size_t bufferByteSize = bufferSideLength * bufferSideLength * sizeof(GLfloat) * 4; densityDiscomfortVelocityTripple = new TextureBufferTripple(bufferByteSize, NULL, GL_DYNAMIC_COPY, GL_RGBA32F, CL_MEM_READ_WRITE, context); totalBufferSize += bufferByteSize; // // Create renderer to render base discomfort map to framebuffer // std::vector<QString> filenamesVert; std::vector<QString> filenamesFrag; filenamesVert.push_back("src/shaders/shared.vert"); filenamesFrag.push_back("src/shaders/shared.frag"); filenamesFrag.push_back("src/shaders/prepareFramebuffer.frag"); prepareFramebufferRenderer = new TextureRenderer(bufferSideLength, baseDiscomfort, filenamesVert, filenamesFrag, "Framebuffer Preparation Shader", false); // // Create shader to render discomfort at pointer to framebuffer // initDiscomfortShaderProgram(); }