neo187

Members
  • Content count

    66
  • Joined

  • Last visited

Community Reputation

100 Neutral

About neo187

  • Rank
    Member
  1. Ok, have yet again refactored the function, this time using one interleaved dynamic array GLfloat displayList that I initialize onLoad according to the mesh vertex count. I get a fairly good boost, from15 FPS frames to roughly 25 FPS. So thanks for the hint! This is the new function, including the two passes that I do for recreating Nehe's toon shade effect: [code] // ... calculate frame position.... int vCount = 0; for(int i = 0; i < numTriangles; i++) { //Calculate vertices interpolation MD2Triangle* triangle = triangles + i; for(int j = 0; j < 3; j++) { MD2Vertex* v1 = frame1->vertices + triangle->vertices[j]; MD2Vertex* v2 = frame2->vertices + triangle->vertices[j]; Vec3f pos = v1->pos * (1 - frac) + v2->pos * frac; Vec3f normal = v1->normal * (1 - frac) + v2->normal * frac; if (normal[0] == 0 && normal[1] == 0 && normal[2] == 0) { normal = Vec3f(0, 0, 1); } displayList[vCount] = normal[0]; displayList[vCount+1] = normal[1]; displayList[vCount+2] = normal[2]; vCount+=3; MD2TexCoord* texCoord = texCoords + triangle->texCoords[j]; displayList[vCount] = texCoord->texCoordX; displayList[vCount+1] = texCoord->texCoordY; vCount+=2; displayList[vCount] = pos[0]; displayList[vCount+1] = pos[1]; displayList[vCount+2] = pos[2]; vCount +=3; } } glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glNormalPointer(GL_FLOAT, 8*sizeof(float), &displayList[0]); glTexCoordPointer(2, GL_FLOAT, 8*sizeof(float), &displayList[3]); glVertexPointer(3, GL_FLOAT, 8*sizeof(float), &displayList[5]); // Cel-Shading Code = Shade glHint (GL_LINE_SMOOTH_HINT, GL_FASTEST); // Use The Good Calculations ( NEW ) glEnable (GL_LINE_SMOOTH); glEnable (GL_TEXTURE_1D); // Enable 1D Texturing ( NEW ) glBindTexture (GL_TEXTURE_1D, shaderTexture[0]); // Bind Our Texture ( NEW ) glColor3f (1.0f, 1.0f, 1.0f); // Set The Color Of The Model ( NEW ) //PASS 1 glDrawArrays(GL_TRIANGLES, 0, numTriangles * 3); glDisable (GL_TEXTURE_1D); // Disable 1D Textures ( NEW ) //Cel-Shading Code = Outline glEnable (GL_BLEND); // Enable Blending ( NEW ) glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // Set The Blend Mode ( NEW ) glPolygonMode (GL_BACK, GL_LINE); // Draw Backfacing Polygons As Wireframes ( NEW ) glLineWidth (outlineWidth); // Set The Line Width ( NEW ) glCullFace (GL_FRONT); // Don't Draw Any Front-Facing Polygons ( NEW ) glDepthFunc (GL_LEQUAL); // Change The Depth Mode ( NEW ) glColor3fv (&outlineColor[0]); // Set The Outline Color ( NEW ) //PASS 2 glDrawArrays(GL_TRIANGLES, 0, numTriangles * 3); glDepthFunc (GL_LESS); // Reset The Depth-Testing Mode ( NEW ) glCullFace (GL_BACK); // Reset The Face To Be Culled ( NEW ) glPolygonMode (GL_BACK, GL_FILL); // Reset Back-Facing Polygon Drawing Mode ( NEW ) glDisable (GL_BLEND); glDisableClientState(GL_VERTEX_ARRAY); // disable vertex arrays glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); [/code] Does this look as efficient as I can get without using vertex shaders? Thanks a lot for your directions!
  2. [quote name='mhagain' timestamp='1322130883' post='4887193'] Also consider interleaving your arrays; non-interleaved arrays are slower with hardware T&L. [/quote] Thank you very much.... I actually do know the maximum number of vertices upfront since the MD2 format has that for its limit, it's 2048.... So if I instead use a Glfloat vertices[2048] array and insert those data in the array at each pass then that should be faster? How can I interleave the data in one array? I understand that I'd have tio use the same array reference in VertexPointer, TextCoordPointer and NormalPointer, but how do I work out the other two members? Thanks a lot for your help!
  3. Have updated my original question as I got past the optimization problems I was facing, can anyone have a look at the way I am using glDrawArrays here as check whether I am using it correctly? As it is currently giving me a worse performance than the original function with immediate drawing mode.... Thanks a lot
  4. [size=2]I have actually (somehow) managed to merge a BMP texture rendering into the effect, the result is actually quite nice and pleasing but it is havling the speed of the program, it's quite very slow even with just 3 models on screen... Since the result was kind of hacked together, I am thinking that maybe I am performing some extra steps or extra rendering tasks that maybe are not needed, and are slowing down the game? Something unnecessary that maybe you guys could spot? Both MD2 and 3DS loader have an InitToon() function called upon creation to load the shader [code]initToon(){ int i; // Looping Variable ( NEW ) char Line[255]; // Storage For 255 Characters ( NEW ) float shaderData[32][3]; // Storate For The 96 Shader Values ( NEW ) FILE *In = fopen ("Shader.txt", "r"); // Open The Shader File ( NEW ) if (In) // Check To See If The File Opened ( NEW ) { for (i = 0; i < 32; i++) // Loop Though The 32 Greyscale Values ( NEW ) { if (feof (In)) // Check For The End Of The File ( NEW ) break; fgets (Line, 255, In); // Get The Current Line ( NEW ) shaderData[i][0] = shaderData[i][1] = shaderData[i][2] = float(atof (Line)); // Copy Over The Value ( NEW ) } fclose (In); // Close The File ( NEW ) } else return false; // It Went Horribly Horribly Wrong ( NEW ) glGenTextures (1, &shaderTexture[0]); // Get A Free Texture ID ( NEW ) glBindTexture (GL_TEXTURE_1D, shaderTexture[0]); // Bind This Texture. From Now On It Will Be 1D ( NEW ) // For Crying Out Loud Don't Let OpenGL Use Bi/Trilinear Filtering! ( NEW ) glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage1D (GL_TEXTURE_1D, 0, GL_RGB, 32, 0, GL_RGB , GL_FLOAT, shaderData); // Upload ( NEW ) }[/code] This is the drawing for the animated MD2 model: [code] void MD2Model::drawToon() { float outlineWidth = 3.0f; // Width Of The Lines ( NEW ) float outlineColor[3] = { 0.0f, 0.0f, 0.0f }; // Color Of The Lines ( NEW ) // ORIGINAL PART OF THE FUNCTION //Figure out the two frames between which we are interpolating int frameIndex1 = (int)(time * (endFrame - startFrame + 1)) + startFrame; if (frameIndex1 > endFrame) { frameIndex1 = startFrame; } int frameIndex2; if (frameIndex1 < endFrame) { frameIndex2 = frameIndex1 + 1; } else { frameIndex2 = startFrame; } MD2Frame* frame1 = frames + frameIndex1; MD2Frame* frame2 = frames + frameIndex2; //Figure out the fraction that we are between the two frames float frac = (time - (float)(frameIndex1 - startFrame) / (float)(endFrame - startFrame + 1)) * (endFrame - startFrame + 1); // I ADDED THESE FROM NEHE'S TUTORIAL FOR FIRST PASS (TOON SHADE) glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); // Use The Good Calculations ( NEW ) glEnable (GL_LINE_SMOOTH); // Cel-Shading Code // glEnable (GL_TEXTURE_1D); // Enable 1D Texturing ( NEW ) glBindTexture (GL_TEXTURE_1D, shaderTexture[0]); // Bind Our Texture ( NEW ) glColor3f (1.0f, 1.0f, 1.0f); // Set The Color Of The Model ( NEW ) // ORIGINAL DRAWING CODE //Draw the model as an interpolation between the two frames glBegin(GL_TRIANGLES); for(int i = 0; i < numTriangles; i++) { MD2Triangle* triangle = triangles + i; for(int j = 0; j < 3; j++) { MD2Vertex* v1 = frame1->vertices + triangle->vertices[j]; MD2Vertex* v2 = frame2->vertices + triangle->vertices[j]; Vec3f pos = v1->pos * (1 - frac) + v2->pos * frac; Vec3f normal = v1->normal * (1 - frac) + v2->normal * frac; if (normal[0] == 0 && normal[1] == 0 && normal[2] == 0) { normal = Vec3f(0, 0, 1); } glNormal3f(normal[0], normal[1], normal[2]); MD2TexCoord* texCoord = texCoords + triangle->texCoords[j]; glTexCoord2f(texCoord->texCoordX, texCoord->texCoordY); glVertex3f(pos[0], pos[1], pos[2]); } } glEnd(); // ADDED THESE FROM NEHE'S FOR SECOND PASS (OUTLINE) glDisable (GL_TEXTURE_1D); // Disable 1D Textures ( NEW ) glEnable (GL_BLEND); // Enable Blending ( NEW ) glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // Set The Blend Mode ( NEW ) glPolygonMode (GL_BACK, GL_LINE); // Draw Backfacing Polygons As Wireframes ( NEW ) glLineWidth (outlineWidth); // Set The Line Width ( NEW ) glCullFace (GL_FRONT); // Don't Draw Any Front-Facing Polygons ( NEW ) glDepthFunc (GL_LEQUAL); // Change The Depth Mode ( NEW ) glColor3fv (&outlineColor[0]); // Set The Outline Color ( NEW ) // HERE I AM PARSING THE VERTICES AGAIN (NOT IN THE ORIGINAL FUNCTION) FOR THE OUTLINE AS PER NEHE'S TUT glBegin (GL_TRIANGLES); // Tell OpenGL What We Want To Draw for(int i = 0; i < numTriangles; i++) { MD2Triangle* triangle = triangles + i; for(int j = 0; j < 3; j++) { MD2Vertex* v1 = frame1->vertices + triangle->vertices[j]; MD2Vertex* v2 = frame2->vertices + triangle->vertices[j]; Vec3f pos = v1->pos * (1 - frac) + v2->pos * frac; Vec3f normal = v1->normal * (1 - frac) + v2->normal * frac; if (normal[0] == 0 && normal[1] == 0 && normal[2] == 0) { normal = Vec3f(0, 0, 1); } glNormal3f(normal[0], normal[1], normal[2]); MD2TexCoord* texCoord = texCoords + triangle->texCoords[j]; glTexCoord2f(texCoord->texCoordX, texCoord->texCoordY); glVertex3f(pos[0], pos[1], pos[2]); } } glEnd (); // Tell OpenGL We've Finished glDepthFunc (GL_LESS); // Reset The Depth-Testing Mode ( NEW ) glCullFace (GL_BACK); // Reset The Face To Be Culled ( NEW ) glPolygonMode (GL_BACK, GL_FILL); // Reset Back-Facing Polygon Drawing Mode ( NEW ) glDisable (GL_BLEND); } [/code] Whereas this is the drawToon function in the 3DS loader [code] void Model_3DS::drawToon() { float outlineWidth = 3.0f; // Width Of The Lines ( NEW ) float outlineColor[3] = { 0.0f, 0.0f, 0.0f }; // Color Of The Lines ( NEW ) //ORIGINAL CODE if (visible) { glPushMatrix(); // Move the model glTranslatef(pos.x, pos.y, pos.z); // Rotate the model glRotatef(rot.x, 1.0f, 0.0f, 0.0f); glRotatef(rot.y, 0.0f, 1.0f, 0.0f); glRotatef(rot.z, 0.0f, 0.0f, 1.0f); glScalef(scale, scale, scale); // Loop through the objects for (int i = 0; i < numObjects; i++) { // Enable texture coordiantes, normals, and vertices arrays if (Objects[i].textured) glEnableClientState(GL_TEXTURE_COORD_ARRAY); if (lit) glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); // Point them to the objects arrays if (Objects[i].textured) glTexCoordPointer(2, GL_FLOAT, 0, Objects[i].TexCoords); if (lit) glNormalPointer(GL_FLOAT, 0, Objects[i].Normals); glVertexPointer(3, GL_FLOAT, 0, Objects[i].Vertexes); // Loop through the faces as sorted by material and draw them for (int j = 0; j < Objects[i].numMatFaces; j ++) { // Use the material's texture Materials[Objects[i].MatFaces[j].MatIndex].tex.Use(); // AFTER THE TEXTURE IS APPLIED I INSERT THE TOON FUNCTIONS HERE (FIRST PASS) glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); // Use The Good Calculations ( NEW ) glEnable (GL_LINE_SMOOTH); // Cel-Shading Code // glEnable (GL_TEXTURE_1D); // Enable 1D Texturing ( NEW ) glBindTexture (GL_TEXTURE_1D, shaderTexture[0]); // Bind Our Texture ( NEW ) glColor3f (1.0f, 1.0f, 1.0f); // Set The Color Of The Model ( NEW ) glPushMatrix(); // Move the model glTranslatef(Objects[i].pos.x, Objects[i].pos.y, Objects[i].pos.z); // Rotate the model glRotatef(Objects[i].rot.z, 0.0f, 0.0f, 1.0f); glRotatef(Objects[i].rot.y, 0.0f, 1.0f, 0.0f); glRotatef(Objects[i].rot.x, 1.0f, 0.0f, 0.0f); // Draw the faces using an index to the vertex array glDrawElements(GL_TRIANGLES, Objects[i].MatFaces[j].numSubFaces, GL_UNSIGNED_SHORT, Objects[i].MatFaces[j].subFaces); glPopMatrix(); } glDisable (GL_TEXTURE_1D); // Disable 1D Textures ( NEW ) // THIS IS AN ADDED SECOND PASS AT THE VERTICES FOR THE OUTLINE glEnable (GL_BLEND); // Enable Blending ( NEW ) glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // Set The Blend Mode ( NEW ) glPolygonMode (GL_BACK, GL_LINE); // Draw Backfacing Polygons As Wireframes ( NEW ) glLineWidth (outlineWidth); // Set The Line Width ( NEW ) glCullFace (GL_FRONT); // Don't Draw Any Front-Facing Polygons ( NEW ) glDepthFunc (GL_LEQUAL); // Change The Depth Mode ( NEW ) glColor3fv (&outlineColor[0]); // Set The Outline Color ( NEW ) for (int j = 0; j < Objects[i].numMatFaces; j ++) { glPushMatrix(); // Move the model glTranslatef(Objects[i].pos.x, Objects[i].pos.y, Objects[i].pos.z); // Rotate the model glRotatef(Objects[i].rot.z, 0.0f, 0.0f, 1.0f); glRotatef(Objects[i].rot.y, 0.0f, 1.0f, 0.0f); glRotatef(Objects[i].rot.x, 1.0f, 0.0f, 0.0f); // Draw the faces using an index to the vertex array glDrawElements(GL_TRIANGLES, Objects[i].MatFaces[j].numSubFaces, GL_UNSIGNED_SHORT, Objects[i].MatFaces[j].subFaces); glPopMatrix(); } glDepthFunc (GL_LESS); // Reset The Depth-Testing Mode ( NEW ) glCullFace (GL_BACK); // Reset The Face To Be Culled ( NEW ) glPolygonMode (GL_BACK, GL_FILL); // Reset Back-Facing Polygon Drawing Mode ( NEW ) glDisable (GL_BLEND); glPopMatrix(); } [/code] Finally this is the tex.Use() function that loads a BMP texture and somehow gets blended perfectly with the Toon shading [code] void GLTexture::Use() { glEnable(GL_TEXTURE_2D); // Enable texture mapping glBindTexture(GL_TEXTURE_2D, texture[0]); // Bind the texture as the current one } [/code][/size]
  5. Hi all The original question for this topic was how to re factor a keyframing/rendering function which uses immediate mode in order to make it more efficient, since I need to make two passes at all the vertices for an after effect. This was the original function [code] void MD2Model::draw() { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, textureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //Figure out the two frames between which we are interpolating int frameIndex1 = (int)(time * (endFrame - startFrame + 1)) + startFrame; if (frameIndex1 > endFrame) { frameIndex1 = startFrame; } int frameIndex2; if (frameIndex1 < endFrame) { frameIndex2 = frameIndex1 + 1; } else { frameIndex2 = startFrame; } MD2Frame* frame1 = frames + frameIndex1; MD2Frame* frame2 = frames + frameIndex2; //Figure out the fraction that we are between the two frames float frac = (time - (float)(frameIndex1 - startFrame) / (float)(endFrame - startFrame + 1)) * (endFrame - startFrame + 1); //Draw the model as an interpolation between the two frames glBegin(GL_TRIANGLES); for(int i = 0; i < numTriangles; i++) { MD2Triangle* triangle = triangles + i; for(int j = 0; j < 3; j++) { MD2Vertex* v1 = frame1->vertices + triangle->vertices[j]; MD2Vertex* v2 = frame2->vertices + triangle->vertices[j]; Vec3f pos = v1->pos * (1 - frac) + v2->pos * frac; Vec3f normal = v1->normal * (1 - frac) + v2->normal * frac; if (normal[0] == 0 && normal[1] == 0 && normal[2] == 0) { normal = Vec3f(0, 0, 1); } glNormal3f(normal[0], normal[1], normal[2]); MD2TexCoord* texCoord = texCoords + triangle->texCoords[j]; glTexCoord2f(texCoord->texCoordX, texCoord->texCoordY); glVertex3f(pos[0], pos[1], pos[2]); } } glEnd(); } [/code] Which after a lot of work I reworked to store the vertices in std::vectors at each pass and display them afterwards with glDrawArrays, which should theoretically be faster.... But it's proving to be a LOT slower for now... Is this function implemented correctly, or am I doing something unnecessary? [code] void MD2Model::drawToon() { float outlineWidth = 3.0f; // Width Of The Lines ( NEW ) float outlineColor[3] = { 0.0f, 0.0f, 0.0f }; // Color Of The Lines ( NEW ) //Figure out the two frames between which we are interpolating int frameIndex1 = (int)(time * (endFrame - startFrame + 1)) + startFrame; if (frameIndex1 > endFrame) { frameIndex1 = startFrame; } int frameIndex2; if (frameIndex1 < endFrame) { frameIndex2 = frameIndex1 + 1; for(int i = 0; i < numTriangles; i++) { MD2Triangle* triangle = triangles + i; for(int j = 0; j < 3; j++) { MD2Vertex* v1 = frame1->vertices + triangle->vertices[j]; MD2Vertex* v2 = frame2->vertices + triangle->vertices[j]; Vec3f pos = v1->pos * (1 - frac) + v2->pos * frac; Vec3f normal = v1->normal * (1 - frac) + v2->normal * frac; if (normal[0] == 0 && normal[1] == 0 && normal[2] == 0) { normal = Vec3f(0, 0, 1); } normals.push_back(normal[0]); normals.push_back(normal[1]); normals.push_back(normal[2]); MD2TexCoord* texCoord = texCoords + triangle->texCoords[j]; textCoords.push_back(texCoord->texCoordX); textCoords.push_back(texCoord->texCoordY); vertices.push_back(pos[0]); vertices.push_back(pos[1]); vertices.push_back(pos[2]); } } glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glNormalPointer(GL_FLOAT, 0, &normals[0]); glTexCoordPointer(2, GL_FLOAT, 0, &textCoords[0]); glVertexPointer(3, GL_FLOAT, 0, &vertices[0]); glDrawArrays(GL_TRIANGLES, 0, vertices.size()/3); glDisableClientState(GL_VERTEX_ARRAY); // disable vertex arrays glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); vertices.clear(); textCoords.clear(); normals.clear(); } [/code] Thanks in advance for any help you may be able to provide
  6. [font=Arial,]Right so I eventually fixed it by removing the Additional Dependency in the Input section of the Linker and instead adding Include and Library directories in in Configuration Properties\VC++ directories.... Most articles I found advise to use the actual full path to the FMOD installation folder, but since I want this project to be portable and self contained, i created a "lib" and "include" folder in my project and put those files in them... (used the directories "\lib" and "\include" in the project properties which I am assuming links to the project folder, have never done this before but am hoping it won't cause dependency issues if I compile this on a different machine)... And on top of this I've added the .dll to the project root folder and now it compiles ok![/font]
  7. I am trying to set up my Sound Manager (FMOD) to play a background music and other action sounds on different channels, as I understand that this is the only way of having simultaneous sounds with FMOD.... My setup is below, if I call `playRepeat` and then `playOnce` the first track stops! [code] void SoundMgr::addSound(char *path, string n){ Sound* s; fmodsys->createSound(path, FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &s); soundMap.insert(pair<string,Sound*>(n, s)); } void SoundMgr::playOnce(string name){ fmodsys->playSound(FMOD_CHANNEL_FREE, soundMap.find(name)->second, true, &fmodchn); fmodchn->setPosition(0, FMOD_TIMEUNIT_PCM); fmodchn->setPaused(false); } void SoundMgr::playRepeat(string name){ fmodsys->playSound(FMOD_CHANNEL_FREE, soundMap.find(name)->second, true, &backChn); backChn->setMode(FMOD_LOOP_NORMAL); backChn->setPosition(0, FMOD_TIMEUNIT_PCM); backChn->setPaused(false); } [/code] ...despite the fact that I AM using two separate channels.... am I missing something?
  8. I am trying to link FMOD to my project, which I did very easily in the past in Visual Studio 2008.... I am re using the same files that I had in said project, I'm wondering if that's maybe the problem (incompatible with VS2010?)... So I have placed the fmodex_vc.lib and the fmodex.dll file in my project directory, added them to my project's solution explorer, then created a SoundMgr.h file which includes the fmod.h file #include "include\fmod\fmod.h" Where fmod.h has been placed in the include\fmod folder and opens ok if i right click on the above code and click "Open Document"... But if I try to write any code at all, including a simple "using namespace FMOD" it tells me that it FMOD is undeclared or unidentified....And any sample code simply wont be recognised.... am I missing any step?
  9. it was indeed GL_LIGHTING.... It needed to be disabled before rendering lines or text! I somehow thought that glClearColor was necessary for resetting the color before a new one was enabled....seems like I'm wrong, should i just remove it from everywhere?
  10. Hello There's something wrong in my code somewhere but for any number of primitives that I draw, despite calling glClearColor and then picking a color with glColor3f, the colors that appear are completely random... So in my Rendering class I cycle through all the objects and call their drawing methods, for primitives they would look like: [code] inline void PrimitiveDrawer::drawWireframePrism(Vector3 pos, float radius, Vector3 col){ glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); glColor3f(col.x, col.y, col.z); glLineWidth(3); glBegin (GL_LINE_LOOP); ... glEnd() [/code] But no matter what color i select I always get different ones... The interesting think is that all primitive lines I draw with this method assume the color of the models that they bound (they are meant to be bounding volumes for meshes)... Could it have to do with the model loaders I am using? This is affecting every shape (outside the ones around the models), where every GL_LINE assumes the same colour (green for some reason), including the glutBitMapCharacter that I am trying to draw... That's the main think that bothers me as I'd like to pick the colour for the text drawing, currently I am doing: [code] void renderBitmapString(float x, float y, void *font,char *string) { char *c; glRasterPos2f(x, y); for (c=string; *c != '\0'; c++) { glutBitmapCharacter(font, *c); } } void drawText(char text[20], float x, float y){ glPushMatrix(); setOrthographicProjection(); glLoadIdentity(); glClearColor( 0, 0, 0, 0 ); glColor4f(0, 0, 1, 1); renderBitmapString(x, y,(void *)font, text); resetPerspectiveProjection(); glPopMatrix(); } [/code] But the text comes up green instead of blue?
  11. Hi all I am a beginner to OpenGL, for this school project I am working on I'd like to be able to draw text using FreeFonts.... I checked Nehe's tutorial as well as some other libraries he recommends like the FreeType project or OGLFT but they all seem to require installation of different components on the machine before being able to be used in the project. I need to keep my project completely independed, it comes with its own copies of all the GL files and libs, because the project needs to be compiled and run on a virgin machine by the professor... Having said this, is there any library that can just be linked to the project and packed with it, that allows to read and raw a .tff font, also packed in the project? Worst comes to worst I could even use [url="http://nehe.gamedev.net/tutorial/bitmap_fonts/17002/"]Nehe's Bitmap Fonts[/url] technique but it seems like it relies on a Font inside the Windows system files.... I could definitely go for a Bitmap Font reader as long as I can read it from the project's directory.... Thank you for your help!
  12. Hello all, I was just looking at the [url="http://nehe.gamedev.net/tutorial/cel_shading/25001/"]Cel-Shading tutorial[/url], I understand from the code that the effect is obtained by applying one uni-color texture to the model.... I was wondering if there was a way to have the effect work with a Bitmap texture?.... I understand that the relevant code is: [code] // Cel-Shading Code glEnable (GL_TEXTURE_1D); // Enable 1D Texturing glBindTexture (GL_TEXTURE_1D, shaderTexture[0]); // Bind Our Texture glColor3f (1.0f, 1.0f, 1.0f); .... [/code] After having processed the shader.txt file... Is there a way to run that on a normal bitmap texture? My model loader starts its drawing code with these lines [code] glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, textureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); ... [/code] And then goes on do draw the vertices... Thank you very much!
  13. [quote name='dpadam450' timestamp='1321646341' post='4885387'] glColor4f(...,....,...,alphavariable) [/quote] thanks, I have tried that but I don't really notice any transparency, even when setting it to 0!
  14. Hello I am trying to obtain a simple fadeout effect by having a big textured quad cover the screen with the alpha that gradually increases until being full black... I don't quite understand in what part of the drawing code I should alter the alpha...... I have a wrapper class for textures, this is how I load a texture: [code] void GLTexture::LoadBMP(char *name) { // Create a place to store the texture AUX_RGBImageRec *TextureImage[1]; // Set the pointer to NULL memset(TextureImage,0,sizeof(void *)*1); // Load the bitmap and assign our pointer to it TextureImage[0] = auxDIBImageLoad(name); // Just in case we want to use the width and height later width = TextureImage[0]->sizeX; height = TextureImage[0]->sizeY; // Generate the OpenGL texture id glGenTextures(1, &texture[0]); // Bind this texture to its id glBindTexture(GL_TEXTURE_2D, texture[0]); // Use mipmapping filter glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Generate the mipmaps gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); // Cleanup if (TextureImage[0]) { if (TextureImage[0]->data) free(TextureImage[0]->data); free(TextureImage[0]); } } [/code] Then in the drawing section I enable glBlend and activate the texture: [code] gluOrtho2D(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT); glMatrixMode (GL_MODELVIEW); glLoadIdentity(); glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); tex.Use(); //Draw the textured quad here [/code] [code] void GLTexture::Use() { glEnable(GL_TEXTURE_2D); // Enable texture mapping glBindTexture(GL_TEXTURE_2D, texture[0]); // Bind the texture as the current one } [/code] Is there somewhere in this structure that I can implement said effect? Thanks for your help
  15. Hello, I am trying to modify this Digiben sample in order to get the effect of particles that generate from a spot (impact point) and float upwards kind of like the sparks of a fire. The sample has the particles rotating in a circle... I have tried removing the cosine/sine functions and replace them with a normal glTranslate with increasing Y value but I just can't get any real results... could anyone please point out roughly where I should add/modify the translation in this code to obtain that result? [code] void ParticleMgr::init(){ tex.Load("part.bmp"); GLfloat angle = 0; // A particle's angle GLfloat speed = 0; // A particle's speed // Create all the particles for(int i = 0; i < P_MAX; i++) { speed = float(rand()%50 + 450); // Make a random speed // Init the particle with a random speed InitParticle(particle[i],speed,angle); angle += 360 / (float)P_MAX; // Increment the angle so when all the particles are // initialized they will be equally positioned in a // circular fashion } } [/code] [code] void ParticleMgr::InitParticle(PARTICLE &particle, GLfloat sss, GLfloat aaa) { particle.speed = sss; // Set the particle's speed particle.angle = aaa; // Set the particle's current angle of rotation // Randomly set the particles color particle.red = rand()%255; particle.green = rand()%255; particle.blue = rand()%255; } [/code] [code] void ParticleMgr::DrawParticle(const PARTICLE &particle) { tex.Use(); // Calculate the current x any y positions of the particle based on the particle's // current angle -- This will make the particles move in a "circular pattern" GLfloat xPos = sinf(particle.angle); GLfloat yPos = cosf(particle.angle); // Translate to the x and y position and the #defined PDEPTH (particle depth) glTranslatef(xPos,yPos,PDEPTH); // Draw the first quad glBegin(GL_QUADS); glTexCoord2f(0,0); glVertex3f(-5, 5, 0); glTexCoord2f(1,0); glVertex3f(5, 5, 0); glTexCoord2f(1,1); glVertex3f(5, -5, 0); glTexCoord2f(0,1); glVertex3f(-5, -5, 0); glEnd(); // Done drawing quad // Draw the SECOND part of our particle tex.Use(); glRotatef(particle.angle,0,0,1); // Rotate around the z-axis (depth axis) //glTranslatef(0, particle.angle, 0); // Draw the second quad glBegin(GL_QUADS); glTexCoord2f(0,0); glVertex3f(-4, 4, 0); glTexCoord2f(1,0); glVertex3f(4, 4, 0); glTexCoord2f(1,1); glVertex3f(4, -4, 0); glTexCoord2f(0,1); glVertex3f(-4, -4, 0); glEnd(); // Done drawing quad // Translate back to where we began glTranslatef(-xPos,-yPos,-PDEPTH); } [/code] [code] void ParticleMgr::run(){ for(int i = 0; i < P_MAX; i++) { DrawParticle(particle[i]); // Increment the particle's angle particle[i].angle += ANGLE_INC; } } [/code] For now I am adding a glPushMatrix(), glTranslate(x, y, z) in the run() function above, right before the loop, with x,y,z as the position of the enemy for placing them on top of the enemy....is that the best place for that? Thanks for any input!