Jump to content

  • Log In with Google      Sign In   
  • Create Account

neo187

Member Since 02 Nov 2010
Offline Last Active Dec 05 2011 09:16 AM

Topics I've Started

glDrawArrays efficiency issue for a keyframing function

22 November 2011 - 07:44 AM

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


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();
}

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?

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();
}

Thanks in advance for any help you may be able to provide

FMOD - play multiple sounds simultaneously?

21 November 2011 - 05:51 PM

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!
    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);
    	
    }
...despite the fact that I AM using two separate channels.... am I missing something?

c++ linker problem - unable to link FMOD library to VS2010 project

21 November 2011 - 02:18 PM

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?

glColor not working, random color appearing

21 November 2011 - 09:55 AM

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:
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()

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:

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();
}
But the text comes up green instead of blue?

An easy and portable FreeType font library?

21 November 2011 - 07:39 AM

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 Nehe's Bitmap Fonts 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!

PARTNERS