// Compute of the DSP, adding the controls to the input/output passed void remote_dsp_aux::compute(int count, FAUSTFLOAT** input, FAUSTFLOAT** output){ if (fRunningFlag) { // If count > fBufferSize : the cycle is divided in numberOfCycles NetJack cycles, and a lastCycle one int numberOfCycles = count/fBufferSize; int lastCycle = count%fBufferSize; int i = 0; for (i = 0; i < numberOfCycles; i++) { setupBuffers(input, output, i*fBufferSize); ControlUI::encode_midi_control(fControlInputs[0], fInControl, fCounterIn); sendSlice(fBufferSize); recvSlice(fBufferSize); ControlUI::decode_midi_control(fControlOutputs[0], fOutControl, fCounterOut); } if (lastCycle > 0) { setupBuffers(input, output, i*fBufferSize); ControlUI::encode_midi_control(fControlInputs[0], fInControl, fCounterIn); fillBufferWithZerosOffset(getNumInputs(), lastCycle, fBufferSize-lastCycle, fAudioInputs); sendSlice(lastCycle); recvSlice(lastCycle); ControlUI::decode_midi_control(fControlOutputs[0], fOutControl, fCounterOut); } } else { fillBufferWithZerosOffset(getNumOutputs(), 0, count, output); } }
int init_resources(void) { try{ player.moveLeft(9); player.moveForward(7); player.rotateX(-M_PI*3/4); player.rotateY(M_PI/12); player.addForce(gravity*-1); player.loadObj("crazy.o"); cube.loadObj("cube.o"); cube2.loadObj("cube.o"); setupBuffers(player); setupBuffers(cube); setupBuffers(cube2); addObjectToShader(&cube); addObjectToShader(&cube2); bool c1 = cube.loadShaders(vertexShaderFileName, fragmentShaderFileName), c2 = cube2.loadShaders(vertexShaderFileName, fragmentShaderFileName); Vector3 pos = cube2.getPosition()+ Vector3(0.5f, 3.5f, 1.5f); cube2.setPosition(pos); //cube2.setRotation(Vector3(30*M_PI/180, 0, 40*M_PI/180)); return c1 * c2; }catch(int i){ return 0; } }
void __AGE Sprite::reloadOpenGLObjects() { // we assume that the buffer objects are invalid now vertexBuffer = 0; indexBuffer = 0; setupBuffers(); }
__AGE Button::Button( const Resource& gui_tex, const Resource& _font, Layer layer, unsigned short type) :Entity(layer,type), guiTexture(gui_tex), font(_font), textEntity(0), vertexBuffer(0), normalSubtex(-1), hoverSubtex(-1), pressedSubtex(-1), state(0), mouse_id(0), width(0), height(0) { // // Try default subtex names // if( guiTexture.data.texture->subtexNameMap.count("button_normal") ) { normalSubtex = guiTexture.data.texture->subtexNameMap["button_normal"]; } if( guiTexture.data.texture->subtexNameMap.count("button_hover") ) { hoverSubtex = guiTexture.data.texture->subtexNameMap["button_hover"]; } if( guiTexture.data.texture->subtexNameMap.count("button_pressed") ) { pressedSubtex = guiTexture.data.texture->subtexNameMap["button_pressed"]; } if( normalSubtex >= 0 ) setupBuffers(); computeClickBoundingBox(); }
int main(int argc, char** argv){ setupVideoWriting(); int width = image_width; int height = image_height; setupBoard(width, height, argc, argv); setupScreen(width, height); initShaders(); loadTexture(); setupTexture(); setupBuffers(); glutDisplayFunc(&drawScene); glutIdleFunc(&replay); glutMainLoop(); cvReleaseVideoWriter(&writer); return 0; }
__AGE Sprite::Sprite( const __AGE Resource& _texture , __AGE Layer layer, unsigned short type) :Entity(layer, type), texture(_texture), _offsetX(0), _offsetY(0), _flipX(false), _flipY(false), frame(0), nFrames(0), vertexBuffer(0), indexBuffer(0), currentAnimation(0), nextFreeAnimationId(1) { if( texture.type != RESOURCE_TEXTURE ) { texture = Resource(); } else { // compute width and height if( texture.data.texture->subtexCount > 0 ) { GLfloat* texcoords = texture.data.texture->texcoords; GLfloat w = texcoords[2] - texcoords[0]; GLfloat h = texcoords[5] - texcoords[1]; _width = w*texture.data.texture->width; _height = h*texture.data.texture->height; } else // no subtextures -> use whole texture { _width = texture.data.texture->width; _height = texture.data.texture->height; } setupBuffers(); } }
bool Camera::dequeueOne() { if(buffers == NULL) { setupBuffers(); } return buffers->dequeueOne(); }
void __AGE Text::reloadOpenGLObjects() { vertexBuffer = 0; indexBuffer = 0; delete[] bufferTmp; bufferTmp = 0; setupBuffers(); }
void LightRays::setup(int w, int h) { fbo_w = w; fbo_h = h; setupShaders(); setupBuffers(); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); }
void DepthOfField::setup(int w, int h) { fbo_w = w; fbo_h = h; glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); setupShaders(); setupBuffers(); setupFBO(); }
//----------------------------------------------------------------------- void BillboardChain::updateIndexBuffer(void) { setupBuffers(); if (mIndexContentDirty) { uint16* pShort = static_cast<uint16*>( mIndexData->indexBuffer->lock(HardwareBuffer::HBL_DISCARD)); mIndexData->indexCount = 0; // indexes for (ChainSegmentList::iterator segi = mChainSegmentList.begin(); segi != mChainSegmentList.end(); ++segi) { ChainSegment& seg = *segi; // Skip 0 or 1 element segment counts if (seg.head != SEGMENT_EMPTY && seg.head != seg.tail) { // Start from head + 1 since it's only useful in pairs size_t laste = seg.head; while(1) // until break { size_t e = laste + 1; // Wrap forwards if (e == mMaxElementsPerChain) e = 0; // indexes of this element are (e * 2) and (e * 2) + 1 // indexes of the last element are the same, -2 assert (((e + seg.start) * 2) < 65536 && "Too many elements!"); uint16 baseIdx = static_cast<uint16>((e + seg.start) * 2); uint16 lastBaseIdx = static_cast<uint16>((laste + seg.start) * 2); *pShort++ = lastBaseIdx; *pShort++ = lastBaseIdx + 1; *pShort++ = baseIdx; *pShort++ = lastBaseIdx + 1; *pShort++ = baseIdx + 1; *pShort++ = baseIdx; mIndexData->indexCount += 6; if (e == seg.tail) break; // last one laste = e; } } } mIndexData->indexBuffer->unlock(); mIndexContentDirty = false; } }
bool SHM_Transporter::connectServer(Uint32 timeOutMillis){ if(!_shmSegCreated) { char szName[32]; sprintf(szName, "ndb%lu", shmKey); hFileMapping = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, shmSize, szName); if(!hFileMapping) { reportThreadError(remoteNodeId, TE_SHM_UNABLE_TO_CREATE_SEGMENT); NdbSleep_MilliSleep(timeOutMillis); return false; } _shmSegCreated = true; } if(!_attached){ shmBuf = (char*)MapViewOfFile(hFileMapping, FILE_MAP_ALL_ACCESS, 0, 0, 0); if(shmBuf == 0){ reportThreadError(remoteNodeId, TE_SHM_UNABLE_TO_ATTACH_SEGMENT); NdbSleep_MilliSleep(timeOutMillis); return false; } volatile Uint32 * sharedCountAttached = (volatile Uint32*)(shmBuf + 6*sizeof(Uint32*)); ++*sharedCountAttached; _attached = true; } volatile Uint32 * sharedCountAttached = (volatile Uint32*)(shmBuf + 6*sizeof(Uint32*)); if(*sharedCountAttached == 2 && !setupBuffersDone) { setupBuffers(); setupBuffersDone=true; } if(*sharedCountAttached > 2) { reportThreadError(remoteNodeId, TE_SHM_DISCONNECT); return false; } if(setupBuffersDone) { NdbSleep_MilliSleep(timeOutMillis); if(*serverStatusFlag==1 && *clientStatusFlag==1) return true; } NdbSleep_MilliSleep(timeOutMillis); return false; }
void VertBatch::draw() { // this pushes the VAO, which needs to be popped setupBuffers(); ScopedVao vao( mVao ); auto ctx = context(); ctx->setDefaultShaderVars(); ctx->drawArrays( mPrimType, 0, (GLsizei)mVertices.size() ); }
DriverFrame* Camera::grabTemporaryFrame() { if(!isStreaming() && !streamOn()) { fprintf(stderr, "Camera could not grab frame: streaming could not be turned on.\n"); return NULL; } if(buffers == NULL) { setupBuffers(); } return buffers->grabTemporaryFrame(); }
void SSAO::setup(int w, int h) { fbo_w = w; fbo_h = h; glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); setupShaders(); setupBuffers(); setupFBO(); loadImages(); mm.identity(); mm.scale(0.8f); mm.translate(0.0f, -50.0f, 0.0f); }
void __AGE Text::setDynamic( bool value ) { if( _dynamic != value ) { _dynamic = value; glDeleteBuffers(1,&vertexBuffer); glDeleteBuffers(1,&indexBuffer); vertexBuffer = 0; indexBuffer = 0; delete[] bufferTmp; bufferTmp = 0; setupBuffers(); } }
void mesh::loadMesh(std::string fileLocation) { //assumes pattern: //vert count, tri count //vertices, triangles, normals, texcoords std::ifstream fileStream(fileLocation); fileStream >> vertCount; fileStream >> triCount; triangles.resize(3 * triCount); normals.resize(3 * vertCount); vertices.resize(3 * vertCount); texCoords.resize(2 * vertCount); std::string trash; fileStream >> trash; //read and store vertex positions for(int i = 0; i < 3*vertCount; i++) { fileStream >> vertices[i]; } fileStream >> trash; //read and store triangles (vertex indices) for(int j = 0; j < 3*triCount; j++) { fileStream >> triangles[j]; } fileStream >> trash; //read and store normals for(int k = 0; k < 3*vertCount; k++) { fileStream >> normals[k]; } fileStream >> trash; //read and store texture coordinates for(int l = 0; l < 2*vertCount; l++) { fileStream >> texCoords[l]; } fileStream.close(); calculateTangents(); setupBuffers(); }
void __AGE Text::setText( const std::string& value ) { _text = value; // buffer resize needed? if( _text.size() > bufferSizeInChars || _text.size() < bufferSizeInChars/2 ) { glDeleteBuffers(1,&vertexBuffer); glDeleteBuffers(1,&indexBuffer); vertexBuffer = 0; indexBuffer = 0; delete[] bufferTmp; bufferTmp = 0; } setupBuffers(); }
int main(int argc, char **argv) { int argi; for (argi = 0; argi < argc; ++argi) { /* Dump intermediate ELF files */ if (!strcmp(argv[argi], "-v")) { argi++; dump_vertex = 1; continue; } } glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(100,100); glutInitWindowSize(320,320); glutCreateWindow("GLSL Solid Triangles Overlap"); glutDisplayFunc(renderScene); glutIdleFunc(renderScene); glutReshapeFunc(changeSize); glutKeyboardFunc(processNormalKeys); glEnable(GL_DEPTH_TEST); glClearColor(0.0,0.0,0.0,1.0); glewInit(); if (glewIsSupported("GL_VERSION_3_3")) printf("Ready for OpenGL 3.3\n"); else { printf("OpenGL 3.0 not supported\n"); exit(1); } p = setupShaders(); setupBuffers(); glutMainLoop(); return 0; }
ParticleShaderVoronoi::ParticleShaderVoronoi(Particles *ps) :ParticleShader(ps,std::string("ParticleShaderVoronoi")) { quad=gluNewQuadric(); new Attached<ParticlePosition>(this,&position); new Attached<ParticleNormal>(this,&orientation); new PSParamString(this,&radius_source,"AdaptiveRepulsionData:radius","radattr","radius source", "Source of the radius of the form Attribute:param"); new PSParamDouble(this,&scale,1.35,"scale","scale factor", "Amount to scale the radius"); new PSParamDouble(this,&toleranceScale,1.8,"tolerance scale", "Number of radii we limit fragments to"); radius_attr = NULL; radius_data = NULL; pbufferOne = NULL; // Get the current viewport size GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); // Check to make sure the necessary extensions are supported pbufferOne->testExtensions(); // Setup the pbuffers setupBuffers(viewport[2], viewport[3]); // Setup textures glGenTextures(1, &depth_texture); glBindTexture(GL_TEXTURE_RECTANGLE_NV, depth_texture); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Setup the CG environment setupCG(); }
int main(int argc, char **argv) { // sets up glut glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(100,100); glutInitWindowSize(640,480); glutCreateWindow("ICS Graphics"); glutSetWindowTitle(s); // call back functions glutDisplayFunc(renderScene); glutIdleFunc(renderScene); glutReshapeFunc(changeSize); glutMouseFunc(mouseButton); glutMotionFunc(mouseMove); glutKeyboardFunc(readKeyboard); // check if a particular extension is available on your platform // Originally designed for OpenGL 4.4, but we lowered the version to 3.3, however, the project name remains 4_4. glewInit(); if (glewIsSupported("GL_VERSION_3_3")) printf("OpenGL 3.3 is supported\n"); else { printf("OpenGL 3.3 not supported\n"); exit(1); } glEnable(GL_DEPTH_TEST); glClearColor(1.0,1.0,1.0,1.0); //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); init(); p = initShaders(); setupBuffers(); glutMainLoop(); return(0); }
void __AGE Button::setButtonTextures( const std::string& normal, const std::string& hover, const std::string& pressed ) { if( guiTexture.data.texture->subtexNameMap.count(normal) ) { normalSubtex = guiTexture.data.texture->subtexNameMap[normal]; } if( guiTexture.data.texture->subtexNameMap.count(hover) ) { hoverSubtex = guiTexture.data.texture->subtexNameMap[hover]; } if( guiTexture.data.texture->subtexNameMap.count(pressed) ) { pressedSubtex = guiTexture.data.texture->subtexNameMap[pressed]; } if( normalSubtex >= 0 ) setupBuffers(); computeClickBoundingBox(); }
bool SHM_Transporter::connect_common(NDB_SOCKET_TYPE sockfd) { if (!checkConnected()) { return false; } if(!setupBuffersDone) { setupBuffers(); setupBuffersDone=true; } if(setupBuffersDone) { NdbSleep_MilliSleep(m_timeOutMillis); if(*serverStatusFlag == 1 && *clientStatusFlag == 1) return true; } DBUG_PRINT("error", ("Failed to set up buffers to node %d", remoteNodeId)); return false; }
//----------------------------------------------------------------------- void PUBillboardChain::updateIndexBuffer(void) { setupBuffers(); if (_indexContentDirty) { //uint16* pShort = static_cast<uint16*>( // _indexData->indexBuffer->lock(HardwareBuffer::HBL_DISCARD)); //_indexData->indexCount = 0; // indexes unsigned short index = 0; for (ChainSegmentList::iterator segi = _chainSegmentList.begin(); segi != _chainSegmentList.end(); ++segi) { ChainSegment& seg = *segi; // Skip 0 or 1 element segment counts if (seg.head != SEGMENT_EMPTY && seg.head != seg.tail) { // Start from head + 1 since it's only useful in pairs size_t laste = seg.head; while(1) // until break { size_t e = laste + 1; // Wrap forwards if (e == _maxElementsPerChain) e = 0; // indexes of this element are (e * 2) and (e * 2) + 1 // indexes of the last element are the same, -2 CCASSERT (((e + seg.start) * 2) < 65536, "Too many elements!"); unsigned short baseIdx = static_cast<unsigned short>((e + seg.start) * 2); unsigned short lastBaseIdx = static_cast<unsigned short>((laste + seg.start) * 2); //*pShort++ = lastBaseIdx; //*pShort++ = lastBaseIdx + 1; //*pShort++ = baseIdx; //*pShort++ = lastBaseIdx + 1; //*pShort++ = baseIdx + 1; //*pShort++ = baseIdx; //_indexData->indexCount += 6; _indices[index++] = lastBaseIdx; _indices[index++] = lastBaseIdx + 1; _indices[index++] = baseIdx; _indices[index++] = lastBaseIdx + 1; _indices[index++] = baseIdx + 1; _indices[index++] = baseIdx; if (e == seg.tail) break; // last one laste = e; } } } _indexBuffer->updateIndices(&_indices[0], (int)_indices.size(), 0); //_indexData->indexBuffer->unlock(); _indexContentDirty = false; } }
//----------------------------------------------------------------------- void PUBillboardChain::updateVertexBuffer(const Mat4 &camMat) { setupBuffers(); // The contents of the vertex buffer are correct if they are not dirty // and the camera used to build the vertex buffer is still the current // camera. if (!_vertexContentDirty) return; VertexInfo vi = {Vec3(0.0f, 0.0f, 0.0f), Vec2(0.0f, 0.0f), Vec4::ONE}; _vertices.assign(_vertices.size(), vi); //HardwareVertexBufferSharedPtr pBuffer = // _vertexData->vertexBufferBinding->getBuffer(0); //void* pBufferStart = pBuffer->lock(HardwareBuffer::HBL_DISCARD); //const Vector3& camPos = cam->getDerivedPosition(); //Vector3 eyePos = mParentNode->_getDerivedOrientation().Inverse() * // (camPos - mParentNode->_getDerivedPosition()) / mParentNode->_getDerivedScale(); Vec3 eyePos = Vec3(camMat.m[12], camMat.m[13], camMat.m[14]); Vec3 chainTangent; for (ChainSegmentList::iterator segi = _chainSegmentList.begin(); segi != _chainSegmentList.end(); ++segi) { ChainSegment& seg = *segi; // Skip 0 or 1 element segment counts if (seg.head != SEGMENT_EMPTY && seg.head != seg.tail) { size_t laste = seg.head; for (size_t e = seg.head; ; ++e) // until break { // Wrap forwards if (e == _maxElementsPerChain) e = 0; Element& elem = _chainElementList[e + seg.start]; CCASSERT (((e + seg.start) * 2) < 65536, "Too many elements!"); unsigned short vertexIndex = static_cast<unsigned short>((e + seg.start) * 2); //// Determine base pointer to vertex #1 //void* pBase = static_cast<void*>( // static_cast<char*>(pBufferStart) + // pBuffer->getVertexSize() * baseIdx); // Get index of next item size_t nexte = e + 1; if (nexte == _maxElementsPerChain) nexte = 0; if (e == seg.head) { // No laste, use next item chainTangent = _chainElementList[nexte + seg.start].position - elem.position; } else if (e == seg.tail) { // No nexte, use only last item chainTangent = elem.position - _chainElementList[laste + seg.start].position; } else { // A mid position, use tangent across both prev and next chainTangent = _chainElementList[nexte + seg.start].position - _chainElementList[laste + seg.start].position; } Vec3 vP1ToEye; //if( _faceCamera ) vP1ToEye = eyePos - elem.position; //else // vP1ToEye = elem.orientation * _normalBase; Vec3 vPerpendicular; Vec3::cross(chainTangent, vP1ToEye, &vPerpendicular); vPerpendicular.normalize(); vPerpendicular *= (elem.width * 0.5f); Vec3 pos0 = elem.position - vPerpendicular; Vec3 pos1 = elem.position + vPerpendicular; //float* pFloat = static_cast<float*>(pBase); //// pos1 //*pFloat++ = pos0.x; //*pFloat++ = pos0.y; //*pFloat++ = pos0.z; _vertices[vertexIndex + 0].position = pos0; //pBase = static_cast<void*>(pFloat); if (_useVertexColour) { //RGBA* pCol = static_cast<RGBA*>(pBase); //Root::getSingleton().convertColourValue(elem.colour, pCol); //pCol++; //pBase = static_cast<void*>(pCol); _vertices[vertexIndex + 0].color = elem.color; } if (_useTexCoords) { //pFloat = static_cast<float*>(pBase); if (_texCoordDir == TCD_U) { //*pFloat++ = elem.texCoord; //*pFloat++ = _otherTexCoordRange[0]; _vertices[vertexIndex + 0].uv.x = elem.texCoord; _vertices[vertexIndex + 0].uv.y = _otherTexCoordRange[0]; } else { //*pFloat++ = _otherTexCoordRange[0]; //*pFloat++ = elem.texCoord; _vertices[vertexIndex + 0].uv.x = _otherTexCoordRange[0]; _vertices[vertexIndex + 0].uv.y = elem.texCoord; } //pBase = static_cast<void*>(pFloat); } // pos2 //pFloat = static_cast<float*>(pBase); //*pFloat++ = pos1.x; //*pFloat++ = pos1.y; //*pFloat++ = pos1.z; //pBase = static_cast<void*>(pFloat); _vertices[vertexIndex + 1].position = pos1; if (_useVertexColour) { //RGBA* pCol = static_cast<RGBA*>(pBase); //Root::getSingleton().convertColourValue(elem.colour, pCol); //pCol++; //pBase = static_cast<void*>(pCol); _vertices[vertexIndex + 1].color = elem.color; } if (_useTexCoords) { //pFloat = static_cast<float*>(pBase); if (_texCoordDir == TCD_U) { //*pFloat++ = elem.texCoord; //*pFloat++ = _otherTexCoordRange[1]; _vertices[vertexIndex + 1].uv.x = elem.texCoord; _vertices[vertexIndex + 1].uv.y = _otherTexCoordRange[1]; } else { //*pFloat++ = _otherTexCoordRange[1]; //*pFloat++ = elem.texCoord; _vertices[vertexIndex + 1].uv.x = _otherTexCoordRange[1]; _vertices[vertexIndex + 1].uv.y = elem.texCoord; } } if (e == seg.tail) break; // last one laste = e; //vertexIndex += 2; } // element } // segment valid? } // each segment _vertexBuffer->updateVertices(&_vertices[0], (int)_vertices.size(), 0);; //pBuffer->unlock(); //_vertexCameraUsed = cam; _vertexContentDirty = false; }
void __AGE Button::reloadOpenGLObjects() { vertexBuffer = 0; setupBuffers(); }
//----------------------------------------------------------------------- void BillboardChain::updateVertexBuffer(Camera* cam) { setupBuffers(); HardwareVertexBufferSharedPtr pBuffer = mVertexData->vertexBufferBinding->getBuffer(0); void* pBufferStart = pBuffer->lock(HardwareBuffer::HBL_DISCARD); const Vector3& camPos = cam->getDerivedPosition(); Vector3 eyePos = mParentNode->_getDerivedOrientation().Inverse() * (camPos - mParentNode->_getDerivedPosition()) / mParentNode->_getDerivedScale(); Vector3 chainTangent; for (ChainSegmentList::iterator segi = mChainSegmentList.begin(); segi != mChainSegmentList.end(); ++segi) { ChainSegment& seg = *segi; // Skip 0 or 1 element segment counts if (seg.head != SEGMENT_EMPTY && seg.head != seg.tail) { size_t laste = seg.head; for (size_t e = seg.head; ; ++e) // until break { // Wrap forwards if (e == mMaxElementsPerChain) e = 0; Element& elem = mChainElementList[e + seg.start]; assert (((e + seg.start) * 2) < 65536 && "Too many elements!"); uint16 baseIdx = static_cast<uint16>((e + seg.start) * 2); // Determine base pointer to vertex #1 void* pBase = static_cast<void*>( static_cast<char*>(pBufferStart) + pBuffer->getVertexSize() * baseIdx); // Get index of next item size_t nexte = e + 1; if (nexte == mMaxElementsPerChain) nexte = 0; if (e == seg.head) { // No laste, use next item chainTangent = mChainElementList[nexte + seg.start].position - elem.position; } else if (e == seg.tail) { // No nexte, use only last item chainTangent = elem.position - mChainElementList[laste + seg.start].position; } else { // A mid position, use tangent across both prev and next chainTangent = mChainElementList[nexte + seg.start].position - mChainElementList[laste + seg.start].position; } Vector3 vP1ToEye; if( mFaceCamera ) vP1ToEye = eyePos - elem.position; else vP1ToEye = elem.orientation * mNormalBase; Vector3 vPerpendicular = chainTangent.crossProduct(vP1ToEye); vPerpendicular.normalise(); vPerpendicular *= (elem.width * 0.5f); Vector3 pos0 = elem.position - vPerpendicular; Vector3 pos1 = elem.position + vPerpendicular; float* pFloat = static_cast<float*>(pBase); // pos1 *pFloat++ = pos0.x; *pFloat++ = pos0.y; *pFloat++ = pos0.z; pBase = static_cast<void*>(pFloat); if (mUseVertexColour) { RGBA* pCol = static_cast<RGBA*>(pBase); Root::getSingleton().convertColourValue(elem.colour, pCol); pCol++; pBase = static_cast<void*>(pCol); } if (mUseTexCoords) { pFloat = static_cast<float*>(pBase); if (mTexCoordDir == TCD_U) { *pFloat++ = elem.texCoord; *pFloat++ = mOtherTexCoordRange[0]; } else { *pFloat++ = mOtherTexCoordRange[0]; *pFloat++ = elem.texCoord; } pBase = static_cast<void*>(pFloat); } // pos2 pFloat = static_cast<float*>(pBase); *pFloat++ = pos1.x; *pFloat++ = pos1.y; *pFloat++ = pos1.z; pBase = static_cast<void*>(pFloat); if (mUseVertexColour) { RGBA* pCol = static_cast<RGBA*>(pBase); Root::getSingleton().convertColourValue(elem.colour, pCol); pCol++; pBase = static_cast<void*>(pCol); } if (mUseTexCoords) { pFloat = static_cast<float*>(pBase); if (mTexCoordDir == TCD_U) { *pFloat++ = elem.texCoord; *pFloat++ = mOtherTexCoordRange[1]; } else { *pFloat++ = mOtherTexCoordRange[1]; *pFloat++ = elem.texCoord; } } if (e == seg.tail) break; // last one laste = e; } // element } // segment valid? } // each segment pBuffer->unlock(); }
int main(int argc, char **argv) { /* glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(100,100); glutInitWindowSize(320,320); if(!glutGet(GLUT_DISPLAY_MODE_POSSIBLE)) { exit(1); } glutCreateWindow("Lighthouse3D"); glutDisplayFunc(renderScene); glutIdleFunc(renderScene); glutReshapeFunc(changeSize); glutKeyboardFunc(processNormalKeys); glewInit(); if (glewIsSupported("GL_VERSION_2_0")) printf("Ready for OpenGL 2.0\n"); else { printf("OpenGL 2.0 not supported\n"); exit(1); } glEnable(GL_DEPTH_TEST); glClearColor(1.0,1.0,1.0,1.0); p = setupShaders(); setupBuffers(); glutMainLoop(); return(0); */ glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(640, 480); if(!glutGet(GLUT_DISPLAY_MODE_POSSIBLE)) { exit(1); } (void)glutCreateWindow("GLUT Program"); glewExperimental = GL_TRUE; glewInit(); if (glewIsSupported("GL_VERSION_2_0")) printf("Ready for OpenGL 2.0\n"); else { printf("OpenGL 2.0 not supported\n"); exit(1); } p = setupShaders(); setupBuffers(); glutDisplayFunc(renderScene); glutIdleFunc(renderScene); glutReshapeFunc(changeSize); glutKeyboardFunc(processNormalKeys); glEnable(GL_DEPTH_TEST); glClearColor(1.0,1.0,1.0,1.0); glutMainLoop(); return EXIT_SUCCESS; }
int init_resources(void) { try{ player.moveLeft(9); player.moveForward(7); player.rotateX(-M_PI*3/4); player.rotateY(M_PI/12); player.addForce(gravity*-1); player.loadObj("crazy.o"); cube.loadObj("cube.o"); cube2.loadObj("cube.o"); setupBuffers(player); setupBuffers(cube); setupBuffers(cube2); addObjectToShader(&cube); addObjectToShader(&cube2); bool c1 = cube.loadShaders(vertexShaderFileName, fragmentShaderFileName), c2 = cube2.loadShaders(vertexShaderFileName, fragmentShaderFileName), c3 = 1; for(int i=0; i< BALLS; i++){ balls[i].loadObj("crazy.o"); balls[i].setScale(Vector3(0.25f,0.25f,0.25f)); setupBuffers(balls[i]); addObjectToShader(&(balls[i])); c3 *= balls[i].loadShaders(vertexShaderFileName, fragmentShaderFileName); balls[i].addVelocity(Vector3(m_rand()-0.5f, m_rand()-0.5f, m_rand()-0.5f).normalize().mult(60.0)); } GLfloat scale_grid = ((GLfloat)DETAIL_GRID*2.0f)/((GLfloat)BOUNDARY); for(int i=0; i< DETAIL_GRID; i++){ for(int j = 0;j < DETAIL_GRID; j++){ grid[i].loadObj("cube.o"); grid[i].setScale(Vector3(scale_grid, scale_grid, scale_grid)); setupBuffers(grid[i]); addObjectToShader(&(grid[i])); c3 *= grid[i].loadShaders(vertexShaderFileName, fragmentShaderFileName); grid[i].setPosition(Vector3(i*scale_grid, j*scale_grid, k*scale_grid - DETAIL_GRID-2.0f)); /*if(i%6 == 0) grid[i].setPosition(Vector3(DETAIL_GRID + 1.0f, (i-3)*scale_grid-DETAIL_GRID, (i-3)*scale_grid-DETAIL_GRID)); else if(i%6 == 1) grid[i].setPosition(Vector3((i-2)*scale_grid-DETAIL_GRID, DETAIL_GRID + 1.0f, (i-2)*scale_grid-DETAIL_GRID)); else if(i%6 == 2) grid[i].setPosition(Vector3((i-1)*scale_grid-DETAIL_GRID, (i-1)*scale_grid-DETAIL_GRID, DETAIL_GRID + 1.0f)); else if(i%6 == 3) grid[i].setPosition(Vector3(-DETAIL_GRID - 1.0f , i*scale_grid-DETAIL_GRID, i*scale_grid-DETAIL_GRID)); else if(i%6 == 4) grid[i].setPosition(Vector3((i+1)*scale_grid-DETAIL_GRID, -DETAIL_GRID - 1.0f, (i+1)*scale_grid-DETAIL_GRID)); else if(i%6 == 5) grid[i].setPosition(Vector3((i+2)*scale_grid-DETAIL_GRID, (i+2)*scale_grid-DETAIL_GRID, -DETAIL_GRID - 1.0f));*/ } } Vector3 pos = cube2.getPosition()+ Vector3(0.5f, 3.5f, 1.5f); cube2.setPosition(pos); //cube2.setRotation(Vector3(30*M_PI/180, 0, 40*M_PI/180)); return c1 * c2 * c3; }catch(int i){ return 0; } }
CVK::Renderable::Renderable() { m_color = glm::vec4(0.0f, 1.0f, 0.0f, 1.0f); setupBuffers(); }