Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


SHOKWAV

Member Since 26 May 2011
Offline Last Active Dec 18 2014 06:46 PM

Topics I've Started

glClearBufferData- How to Use It?

11 December 2012 - 07:24 PM

Hello, I need to learn the proper usage for glClearBufferData for an application I'm creating. I've looked at the official documentation... which isn't very descriptive, mainly what I don't understand are the internalformat, format, and type parameters.

void glClearBufferData( GLenum target,
GLenum internalformat,
GLenum format,
GLenum type,
const void * data);

I have a buffer with a target and some data, and all the data are in float form. I want to clear it all out to 0. Question is, how? Which one do I specify that it's in floats? Internalformat? What about the format and type? I just want to clear out all the memory. I know to specify NULL for data... but what about format and type?

How to Render Only a Section of a Texture (OpenGL 3.1)?

08 December 2012 - 08:29 PM

Hello, I have a problem of which I couldn't seem to find any advice of on Google. I'm using a tileset creator (Tiled) for my game, which takes images and splits them up into tilesets for rendering. I figure this is very efficient and I would like to adopt this in my rendering. However, how can I actually just render a PORTION of a texture in OpenGL? Changing the texture coordinates does nothing more than just move the actual corners of the image. What I want to do is choose what area of the texture to render from, rather than having to split up the image into a bunch of smaller images and load them, which sounds extremely inefficient. Is this a GLSL or an OpenGL problem? Help!

Error When Applying Rotation, Polygon Shrink Over Time?

12 June 2012 - 10:38 PM

I'm making my own polygon class for a game I'm making. However, whenever I try to apply rotation to 'em, it shrinks the entire polygon. After around 1000 rotations the shrinking becomes apparent, and visually you can notice them shrinking rapidly. Is there any way to minimize this? I'm assuming it's some precision errors? Here's my code below, I'm hoping it's enough to see my problem.

(X and Y are macros btw)

void Poly2D::rotateBy(const float angle){

	const float sinA = sinf(angle), cosA = cosf(angle);

	for(ushort i = 0; i < vertLength; i++){

		float &x = vertices[i][X], &y = vertices[i][Y];

		//move to origin for rotating
		x -= center -> x;
		y -= center -> y;

		x = (x * cosA) - (y * sinA);
		y = (x * sinA) + (y * cosA);

		//move back
		x += center -> x;
		y += center -> y;

		std::cout << x << ", " << y << std::endl;

	}
}

OpenGL DrawArrays acting strangely

24 March 2012 - 09:49 AM

Hello. Whenever I try to draw a square using OpenGL's drawarrays function, it acts strange... it draws my square, but it also draws a giant polygon-like thing right below it. I can't get an image (because Vista doesn't capture what I draw with OpenGL with PrntScreen Posted Image), but I was wondering if it was something I am doing wrong?

How I call it: drawSquare(30, 30, 20, 20);


Function:

void drawSquare(const GLshort posX, const GLshort posY, const GLshort sizeX, const GLshort sizeY){


GLshort vertices[8];


//bottom left

vertices[0] = posX;

vertices[1] = posY;

//bottom right

vertices[2] = posX + sizeX;

vertices[3] = posY;

//top right

vertices[4] = posX + sizeX;

vertices[5] = posY - sizeY;

//top left

vertices[6] = posX;

vertices[7] = posY - sizeY;


glEnableClientState(GL_VERTEX_ARRAY);

glEnableClientState(GL_TEXTURE_COORD_ARRAY);


glVertexPointer(2, GL_SHORT, 0, vertices);

glColor4f(1.0f, 1.0f, 0.0f, 0.5f);

glDrawArrays(GL_QUADS, 0, 8);


glDisableClientState(GL_VERTEX_ARRAY);

glDisableClientState(GL_TEXTURE_COORD_ARRAY);

}

Image Doesn't Display?

26 May 2011 - 02:27 PM

Hi, I created a simple class to make drawing on OpenGL easier. I was successfull, until I get into rotation.... now my class won't even show! Am I doing something wrong with matrixs? (It compiles fine, of course, and OpenGL doesn't error...)

classprimitive{

typedef std::vector<GLfloat> v;

typedef std::list<v> v_dat;

v_datvertex_data;

GLfloatrotate_data[3];

GLclampfcolor_data[2];

public:

primitive(constGLclampf r=1.0f, constGLclampf g=0.0f, constGLclampf b=0.0f, constGLclampf angle=0.0f, constGLfloat rotx=0.0f,

constGLfloat roty=0.0f, constGLfloat rotz=0.0f){

rotate_data[0]=angle;

rotate_data[1]=rotx;

rotate_data[2]=roty;

rotate_data[3]=rotz;

color_data[0]=r;

color_data[1]=g;

color_data[2]=b;

}

void addVertex(constGLfloat x, constGLfloat y, constGLfloat z){

v vertex;

vertex.push_back(x);

vertex.push_back(y);

vertex.push_back(z);

vertex_data.push_back(vertex);

}

void draw(constbool swap=true){

std::list<v>::const_iterator i;

glClear(GL_COLOR_BUFFER_BIT);

glPushMatrix();//push matrix stack down and save the current matrix

glRotatef(this->rotate_data[0], this->rotate_data[1], this->rotate_data[2], this->rotate_data[3]);

glBegin(GL_POLYGON);

glColor3f(this->color_data[0], this->color_data[1], this->color_data[2]);

for(i=vertex_data.begin(); i!=vertex_data.end(); i++){

glVertex3f(i->at(0), i->at(1), i->at(2));//i* is a vertex object

}

glEnd();

glPopMatrix();//get the old matrix

if(swap){

SDL_GL_SwapBuffers();

}

}

void flush(){

if(!this->vertex_data.empty()){

this->vertex_data.clear();

}

}

void translate(constGLfloat offx, constGLfloat offy, constGLfloat offz){

std::list<v>::iterator i;

for(i=vertex_data.begin(); i != vertex_data.end(); i++){

i->at(0)=i->at(0)+(offx);

i->at(1)=i->at(1)+(offy);

i->at(2)=i->at(2)+(offz);

}

}

void rotate(constGLfloat angle, constGLfloat x, constGLfloat y, constGLfloat z){

this->rotate_data[0]=angle;

this->rotate_data[1]=x;

this->rotate_data[2]=y;

this->rotate_data[3]=z;

}

void colors(constGLclampf r, constGLclampf g, constGLclampf b){

color_data[0]=r;

color_data[1]=g;

color_data[2]=b;

}

};


PARTNERS