Jump to content

  • Log In with Google      Sign In   
  • Create Account

Wrathnut

Member Since 02 Feb 2000
Offline Last Active Oct 17 2014 03:27 PM

Topics I've Started

Rendering Multiple models problem

12 March 2013 - 01:01 PM

Hi,

 

I think this problem might be related to the one I had the other day. But after an exhaustive search I am still not sure what I am doing wrong. Or if I am trying to render correctly.

 

I was able to get a model to render properly. So my next step was to try to make an stl::vector of different models and try to render them in the same way. When I do this I get some strange effects. I have attached an image of what is going on. I basically arranged a bunch of cubes into a square. It renders the cubes for the most part. (it seems to have messed up the color of one of them though) And then it also draws some extra stuff. I am guessing I am not addressing my models correctly but I am unsure how to do it.

 

I am also wondering if I am even using the right method to draw my models. The code below is when I am using to loop through my vector list of models and try to draw them:

 

        glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);
	
	for(int i=0; i < this->cubes.size(); i++){
		glColorPointer(4, GL_FLOAT, 0, &this->cubes[i]->colors[0]);
		glVertexPointer(3, GL_FLOAT, 0, &this->cubes[i]->vertices[0]);
		glNormalPointer(GL_FLOAT, 0, &this->cubes[i]->normals[0]);

		glDrawArrays(GL_QUADS, 0, this->cubes[i]->vertices.size());
	}

	

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);

 

 

Any help would be greatly appreciated!

 

 


Vertex Arrays

10 March 2013 - 09:06 AM

Hi,

 

I was messing around with openGL and was able to get a simple cube drawn in immediate mode with quads. But I tried moving the cube to a vertex array and drawing the quads and I seem to be having a bit of trouble. If someone could take a look and see if they can spot something obvious I am doing wrong I would really appreciate it.

 

I am using SDL and openGL to do my drawing. The following code is what I am trying to use to render the cube:

 

        //Clear the color buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glTranslatef(0.0f, 0.0f, -10.0f);
	glRotatef(rotation, 1.0f, 1.0f, 0.0f);
        
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
        //glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
        glColorPointer(4, GL_FLOAT, 0, &myCube->colors);
        glVertexPointer(3, GL_FLOAT, 0, &myCube->vertices);

        glDrawArrays(GL_QUADS, 0, myCube->vertices.size());

        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_COLOR_ARRAY);

        glLoadIdentity();

         rotation -= 0.5f;

        //Update Screen    
        SDL_GL_SwapBuffers();

The code I am using to generate the cube vertices and colors are as follows:

 

void model::createCube(float size, float x, float y, float z, float r, float g, float b, float a)
{
	//find half distance
	float half = size / 2.0f;

	//create the top face vertices
	this->vertices.push_back(x-half);	this->vertices.push_back(y+half);	this->vertices.push_back(z+half);
	this->vertices.push_back(x+half);	this->vertices.push_back(y+half);	this->vertices.push_back(z+half);
	this->vertices.push_back(x+half);	this->vertices.push_back(y+half);	this->vertices.push_back(z-half);
	this->vertices.push_back(x-half);	this->vertices.push_back(y+half);	this->vertices.push_back(z-half);

	//Create the top & bottom  face vertex colors
	float tr, tb, tg;
	tr = r / 3.0f;
	tg = g / 3.0f;
	tb = b / 3.0f;
	

	//Add top face vertex colors
	for(int i=0; i < 4; i++){
		this->colors.push_back(tr);		this->colors.push_back(tg);		this->colors.push_back(tb);		this->colors.push_back(a);
	}

	//create the bottom face vertices
	this->vertices.push_back(x-half);	this->vertices.push_back(y-half);	this->vertices.push_back(z+half);
	this->vertices.push_back(x+half);	this->vertices.push_back(y-half);	this->vertices.push_back(z+half);
	this->vertices.push_back(x+half);	this->vertices.push_back(y-half);	this->vertices.push_back(z-half);
	this->vertices.push_back(x-half);	this->vertices.push_back(y-half);	this->vertices.push_back(z-half);

	//Add bottom face vertex colors
	for(int i=0; i < 4; i++){
		this->colors.push_back(tr);		this->colors.push_back(tg);		this->colors.push_back(tb);		this->colors.push_back(a);
	}

	//create the front face vertices
	this->vertices.push_back(x-half);	this->vertices.push_back(y+half);	this->vertices.push_back(z+half);
	this->vertices.push_back(x-half);	this->vertices.push_back(y-half);	this->vertices.push_back(z+half);
	this->vertices.push_back(x+half);	this->vertices.push_back(y-half);	this->vertices.push_back(z+half);
	this->vertices.push_back(x+half);	this->vertices.push_back(y+half);	this->vertices.push_back(z+half);

	//Add front face vertex colors
	for(int i=0; i < 4; i++){
		this->colors.push_back(r);		this->colors.push_back(g);		this->colors.push_back(b);		this->colors.push_back(a);
	}

	//create the back face vertices
	this->vertices.push_back(x-half);	this->vertices.push_back(y+half);	this->vertices.push_back(z-half);
	this->vertices.push_back(x-half);	this->vertices.push_back(y-half);	this->vertices.push_back(z-half);
	this->vertices.push_back(x+half);	this->vertices.push_back(y-half);	this->vertices.push_back(z-half);
	this->vertices.push_back(x+half);	this->vertices.push_back(y+half);	this->vertices.push_back(z-half);

	//Add back face vertex colors
	for(int i=0; i < 4; i++){
		this->colors.push_back(r);		this->colors.push_back(g);		this->colors.push_back(b);		this->colors.push_back(a);
	}

	//create the left face vertices
	this->vertices.push_back(x-half);	this->vertices.push_back(y+half);	this->vertices.push_back(z-half);
	this->vertices.push_back(x-half);	this->vertices.push_back(y-half);	this->vertices.push_back(z-half);
	this->vertices.push_back(x-half);	this->vertices.push_back(y-half);	this->vertices.push_back(z+half);
	this->vertices.push_back(x-half);	this->vertices.push_back(y+half);	this->vertices.push_back(z+half);

	//Create the left & right face vertex colors
	tr = r / 2.0f;
	tg = g / 2.0f;
	tb = b / 2.0f;

	//Add left face vertex colors
	for(int i=0; i < 4; i++){
		this->colors.push_back(tr);		this->colors.push_back(tg);		this->colors.push_back(tb);		this->colors.push_back(a);
	}

	//create the right face vertices
	this->vertices.push_back(x+half);	this->vertices.push_back(y+half);	this->vertices.push_back(z-half);
	this->vertices.push_back(x+half);	this->vertices.push_back(y+half);	this->vertices.push_back(z+half);
	this->vertices.push_back(x+half);	this->vertices.push_back(y-half);	this->vertices.push_back(z+half);
	this->vertices.push_back(x+half);	this->vertices.push_back(y-half);	this->vertices.push_back(z-half);

	//Add left face vertex colors
	for(int i=0; i < 4; i++){
		this->colors.push_back(tr);		this->colors.push_back(tg);		this->colors.push_back(tb);		this->colors.push_back(a);
	}
}

 

 

I have attached some images that show what I am getting rendered. When I try to use the color pointer it appears that only the top face is getting rendered correctly (Aside from the colors not being correct).

 

When I don't use a pointer to the color array and just use one color to render the cube I get the image in red.

 

Does anyone know where I am going wrong on this?

 

Thanks in advance!

 


SFML shaders

01 November 2011 - 05:02 PM

I posted this in the SFML graphics forums but didn't get any response. Not even ,"pixel shaders; you're doing it wrong!"

Anyway I was playing with SFML 1.6 to evaluate it for my next project and tried to modify the tutorial they put together. That seemed to work so my next step was to try to make a flashlight that followed the mouse. My first idea was to try to shade the entire screen to black using the pixel shader but the following code appears to do nothing.

effect 
{ 
     vec3 darkcolor(0.0, 0.0, 0.0); 
     _out = vec4(darkcolor, 1.0); 
} 

Any ideas on why this simple shader doesn't work would be greatly appreciated!

Thanks,

Wrath

simple platformer AI

12 August 2011 - 07:33 PM

Hi,

I have been working on a simple 2d platformer. But recently was thinking about switching out the way I am currently doing AI to using the state pattern as a FSM so I can clean up my code and maybe make it more readable. I am currently just using if..then logic and it is pretty ugly and I envision it getting uglier as I add more enemies with more functionality. Currently my enemy class has a pure virtual function UpateAnimation() and UpdateAI(). Each enemy implementing their own method.

So I am looking for some suggestions on different approaches. I have been toying with the idea of coupling the animation FSM and the AI FSM. I am envisioning something like the AI State will start an animation on entering the state. Thus not requiring an animation state machine. Is this common? Or is it more common to have a seperate FSM for animation and AI? I am a little worried class explosion having to do 2 FSM's for each enemy type(ground based patrols, flying enemies, stationary enemies, swimming enemies, etc..) for the animation and AI. It seems like that would only be exchanging one complexity for another and I am not sure that many classes would be worth it.

Any suggestions would be greatly appreciated. I'd like to get a few ideas rolling around before I forge ahead and possibly realize I took the wrong path.

-Andy

DFT

28 July 2011 - 02:24 PM

I have some quick questions about Discrete Fourier Transforms. I have some magnetometer data being collected in an A/D and wanted to find out some of the frequency info. I am storing the data as a 1D array but have time stamp data for each point. After going over one of my old DSP college books decided to try to use DFT. The book I am using is Fundamentals of DSP by Joyce Van de Vegte. Anyway, it appears that I should be able to transform my digital data into the frequency domain using the following formula:


X[k] = the summation from n = 0 to N-1 of { x[n]*(cos(2*PI*n*(k/N)) - j*sin(2*PI*n*(k/N))) }





where x[n] is the time domain data set and X[k] is the frequency domain data set. So my question is this, Does k refer to the frequency in question or is it just an index. If it is just an index how to I determine what frequency each data point in the set X[k] is at.


Also since X[k] is complex I should just be able to plot the real values for each point and essentially fake a spectrum analyzer(Obviously I would need to convert it to dB)? I noticed in the book they mentioned the DFT magnitude spectrum but this is not the magnitude of the complex value X[k].




Any input is appreciated! Thanks

EDIT: weird formatting errors

PARTNERS