Jump to content

  • Log In with Google      Sign In   
  • Create Account

WiredCat

Member Since 09 Apr 2011
Offline Last Active Yesterday, 11:04 PM

#5302686 I Can't Properly Rotate The Enemy To Look At Me All The Time.

Posted by WiredCat on Yesterday, 05:56 PM

So you shouldnt use angles for that i wont explain whys that. Just vreate a rotation matrix since you will know 2 vectors you are all good firt vector is front enemy-player, second one is the up vector with these two normalized you make cross product and end wirh side vector if front and up aint parallel (i might use wrong word) then you need to normalize that cross product .build a mat out of these 3 vectors and aply it to enemy object simple as hell


#5302680 Billboards Problems

Posted by WiredCat on Yesterday, 05:06 PM

You could extract modelview matix of your camera amd get screen coord up and right vectors in notime


#5300256 Making an object move back and forth.

Posted by WiredCat on 11 July 2016 - 03:50 PM

bool halt;
 
void init()
{
halt = false; //...
}
    void Update ()
    {
if (halt) return;
        transform.Translate(Vector3.right * movementSpeed * Time.deltaTime);
 
    }
 

 

 

 

 

void Execute()

{

 

Update();

halt = (position_between_two_points(transform.pos, some_point) < 10.0); //that acutally will hold position forever so we go with another update function:

 

}

 

 

    void Update ()
    {
if (halt) 
{
//code here
return;
}
        transform.Translate(Vector3.right * movementSpeed * Time.deltaTime);
 
    }
 
 
 
 
 
Nopw look how this is stupid: define a throw object, and make it bool fly; yes or no when it flies it travels then it makes sense 



#5300255 OPenGL:texture mapping problem

Posted by WiredCat on 11 July 2016 - 03:45 PM

from the code in first post, you don't set viewport, additionally i don't see that you enable texturing. 

 

secondary you need to set ortographic projection for glvertex2x would work or set proper projection matrix.

reply for more




#5300250 you all say oculus rift but why not google glass?

Posted by WiredCat on 11 July 2016 - 03:32 PM

same question like in topic. google glass can have the same functionality so why a helmet instead of glasses?




#5297254 About text in OpenGl

Posted by WiredCat on 19 June 2016 - 04:01 PM

to use that you need to setup ortho etc. anyway you use opengl 2.0 and you use fixed function pipeline when you should use shaders.


void glWriteTEXT(int X,int Y, AnsiString text)
{
  glPushAttrib(GL_DEPTH_TEST);  // Save the current Depth test settings (Used for blending )
  glDisable(GL_DEPTH_TEST);     // Turn off depth testing (otherwise we get no FPS)


  glMatrixMode(GL_PROJECTION);  // Switch to the projection matrix
  glPushMatrix();               // Save current projection matrix
  glLoadIdentity();

//  GetWindowRect(GetDesktopWindow(), drawRect);  // Get current window size
  glOrtho(0, WINDOW_WIDTH, 0, WINDOW_HEIGHT, -1, 1);  // Change the projection matrix using an orthgraphic projection
  glMatrixMode(GL_MODELVIEW);  // Return to the modelview matrix
  glPushMatrix();              // Save the current modelview matrix
  glLoadIdentity();
 // glColor3f(1.0, 1.0, 1.0);    // Text color

  glRasterPos2i(X, Y);                                // Position the Text
  glPushAttrib(GL_LIST_BIT);                          // Save's the current base list
  glListBase(base);                              // Set the base list to our character list
  glCallLists(text.Length(), GL_UNSIGNED_BYTE, text.c_str());  // Display the text
  glPopAttrib();                                      // Restore the old base list

  glMatrixMode(GL_PROJECTION);  //Switch to projection matrix
  glPopMatrix();                // Restore the old projection matrix
  glMatrixMode(GL_MODELVIEW);   // Return to modelview matrix
  glPopMatrix();                // Restore old modelview matrix
 // glEnable(GL_TEXTURE_2D);      // Turn on textures, don't want our text textured
 // glEnable(GL_LIGHTING);
  glPopAttrib();                // Restore depth testing


}



#5295264 2d images and OpenGL

Posted by WiredCat on 06 June 2016 - 06:52 AM

this is an example of drawing 2d text as set of 2d textured images (that you load each texture for each character)


struct TFontChar
{
int id;
AnsiString txt;
AnsiString FontName;
TGLTexture texture;
};

struct TFontVertex
{
	t3dpoint<float> v;
	textpoint t;
};

struct TFont
{


	TFont()
	{
		initialized = false;
		font_color = vec3(0.0, 1.0, 0.0);
	}

	~TFont()
	{
if(initialized)
{
	glDeleteBuffers(1, &alphabet_vbuffer);

delete FONT_SHADER;
delete FONT_EVENT_SHADER;
}
	}

AnsiString chartable;
TFontChar * Alphabet;
TFontVertex * FONT_VERTEX_BUFFER;
TShaderObject * FONT_SHADER;
TShaderObject * FONT_EVENT_SHADER;
bool initialized;
vec3 font_color;
unsigned int alphabet_vbuffer;
float sw,sh;
 void initialize_char_table(AnsiString FONT_DIR, float asw, float ash, AnsiString appdir) //additionally load default font for debugging
	{
	 sw=asw;
	 sh=ash;
CAN_LOG = true;
		FONT_SHADER = new TShaderObject();

		FONT_SHADER->LoadShaderProgram(appdir+"shaders/fonts/base_font_vp.shader",appdir+"shaders/fonts/base_font_fp.shader");

		FONT_EVENT_SHADER = new TShaderObject();

		FONT_EVENT_SHADER->LoadShaderProgram(appdir+"shaders/fonts/event_font_vp.shader",appdir+"shaders/fonts/event_font_fp.shader");



		chartable = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-+.,=:{}()[]/*;!<>_?";
int x = chartable.length();
		Alphabet = new TFontChar[ x ];
//		ALOG("alphabet length: "+IntToStr(x));

		for (int i=0; i < chartable.length(); i++)
		{
//ALOG("FONT INDEX: "+IntToStr(i));
			Alphabet[i].texture.px_height = 32;
			Alphabet[i].texture.px_width  = 32;
		Alphabet[i].texture.LoadTGA(appdir+FONT_DIR+IntToStr(i)+".tga");
		Alphabet[i].txt = chartable[i];
		}

		FONT_VERTEX_BUFFER = new TFontVertex[ 256*4 ]; //max 256 chars...
for (int i=0; i < 256; i++)
{

	FONT_VERTEX_BUFFER[i*4+0].t = textpoint(0.0, 0.0);
	FONT_VERTEX_BUFFER[i*4+0].v = t3dpoint<float>(0.0+i*18.0, 0.0, 0.0);
	FONT_VERTEX_BUFFER[i*4+1].t = textpoint(1.0, 0.0);
	FONT_VERTEX_BUFFER[i*4+1].v = t3dpoint<float>(0.0+i*18.0+18.0, 0.0, 0.0);
	FONT_VERTEX_BUFFER[i*4+2].t = textpoint(1.0, 1.0);
	FONT_VERTEX_BUFFER[i*4+2].v = t3dpoint<float>(0.0+i*18.0+18.0, 0.0 + 18.0, 0.0);
	FONT_VERTEX_BUFFER[i*4+3].t = textpoint(0.0, 1.0);
	FONT_VERTEX_BUFFER[i*4+3].v = t3dpoint<float>(0.0, 0.0 + 18.0, 0.0);
}

		glGenBuffers(1, &alphabet_vbuffer);
		glBindBuffer(GL_ARRAY_BUFFER, alphabet_vbuffer);
		glBufferData(GL_ARRAY_BUFFER, sizeof(TFontVertex) * 256 * 4, FONT_VERTEX_BUFFER, GL_STATIC_DRAW);

		glBindBuffer(GL_ARRAY_BUFFER, 0);
		ALOG("DONE WITH LOADING FONT");
		initialized = true;
	}


	 int find_index(char txt)
	{
		for (int i=0; i < chartable.length(); i++)
		{
if (Alphabet[i].txt[0] == txt) return i;
		}

		return 1;
	}



void DrawEventText(float x, float y, float size, vec3 color, float alpha, AnsiString text);


void DrawText(float x, float y, float size, AnsiString atext, vec3 color)
{

	glActiveTexture(GL_TEXTURE0);

	glDisable(GL_DEPTH_TEST);
	glDepthMask(GL_FALSE);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	AnsiString text = UpperCase(atext);

	//lets assume we draw from left top corner of text
	for (int i=0; i < 256; i++)
	{
		FONT_VERTEX_BUFFER[i*4+0].t = textpoint(0.0, 0.0);
		FONT_VERTEX_BUFFER[i*4+0].v = t3dpoint<float>(x+i*size, y, 0.0);

		FONT_VERTEX_BUFFER[i*4+1].t = textpoint(1.0, 0.0);
		FONT_VERTEX_BUFFER[i*4+1].v = t3dpoint<float>(x+i*size+size, y, 0.0);

		FONT_VERTEX_BUFFER[i*4+2].t = textpoint(1.0, 1.0);
		FONT_VERTEX_BUFFER[i*4+2].v = t3dpoint<float>(x+i*size+size, y + size, 0.0);


		FONT_VERTEX_BUFFER[i*4+3].t = textpoint(0.0, 1.0);
		FONT_VERTEX_BUFFER[i*4+3].v = t3dpoint<float>(x+i*size, y + size, 0.0);
	}

	glBindBuffer(GL_ARRAY_BUFFER, alphabet_vbuffer);
	glBufferSubData(GL_ARRAY_BUFFER,0, sizeof(TFontVertex) * 256 * 4, FONT_VERTEX_BUFFER);


	FONT_SHADER->Enable();
	FONT_SHADER->Send1I(glGetUniformLocation(FONT_SHADER->gProgram, "font_tex"), 0 );
	FONT_SHADER->Send3F(glGetUniformLocation(FONT_SHADER->gProgram, "FONT_COLOR"), color );
	FONT_SHADER->Send1F(glGetUniformLocation(FONT_SHADER->gProgram, "sh"), sh );
	FONT_SHADER->Send1F(glGetUniformLocation(FONT_SHADER->gProgram, "sw"), sw );


	glVertexAttribPointer(FONT_SHADER->vertex_pos, 3, GL_FLOAT, GL_FALSE, sizeof(TFontVertex), (void*)(offsetof(struct TFontVertex, v)));
	glVertexAttribPointer(FONT_SHADER->texture_coord, 2, GL_FLOAT, GL_FALSE, sizeof(TFontVertex), (void*)(offsetof(struct TFontVertex, t)));

	glEnableVertexAttribArray(FONT_SHADER->vertex_pos);
	glEnableVertexAttribArray(FONT_SHADER->texture_coord);

		for (int i=0; i < text.length(); i++)
				{
			int index = find_index(text[i]);
				glBindTexture(GL_TEXTURE_2D, Alphabet[ index ].texture.texture);
				glDrawArrays(GL_TRIANGLE_FAN, i*4 , 4);
				}


		glDisableVertexAttribArray(FONT_SHADER->vertex_pos);
		glDisableVertexAttribArray(FONT_SHADER->texture_coord);
	FONT_SHADER->Disable();
		glBindBuffer(GL_ARRAY_BUFFER, 0);


	glDisable(GL_BLEND);
	glDepthMask(GL_TRUE);
	glEnable(GL_DEPTH_TEST);
}

void DrawText(float x, float y, float size, AnsiString atext)
{
	DrawText(x, y, size, atext, font_color);
}

};

fragment shader


uniform sampler2D font_tex;
    varying vec2 texcoord;
 
uniform vec3 FONT_COLOR;
    
void main()
{
vec3 color =    texture2D( font_tex, texcoord ).rgb;
 
float intensity = 0.0;
 
if (color.x > 0.5)
intensity = 0.0;
else
intensity = 1.0;
 
 
 
 
 
gl_FragColor = vec4(FONT_COLOR, intensity);
}
 

 

vertex shader


attribute vec3 Vpos;
attribute vec2 Vtexcoord;
varying vec2 texcoord;
uniform float sw;
uniform float sh;
 
void main()
{
float x = -1.0 + (Vpos.x / sw) * 2.0;
float y = -1.0 + (Vpos.y / sh) * 2.0;
texcoord = Vtexcoord;
gl_Position = vec4(vec2(x,y), 0.0, 1.0);
}
 

 

 

 

Important thing here is that you can define image left, top, width and height in lets say pixels (knowing opengl window size)

 

so you just draw a quad for (one image) that is lets say at top left corner of ogl window:

 

in fragment shader you calculate on screen coordinate (Vpos is vertex position, sw ogl window width, sh ogl window height)

 

float x = -1.0 + (Vpos.x / sw) * 2.0;
float y = -1.0 + (Vpos.y / sh) * 2.0;
 
 
since screen coordinate in ogl is from -1..1 you will put exactly sized image whereever you want



#5292778 Plane equation, + or - D

Posted by WiredCat on 21 May 2016 - 01:18 PM

lol

By this definition, the equation of a plane should be
Ax + By + Cz = D
 
Meaning a point is on the plane if it satisfies:
Ax + By + Cz - D = 0



#5289083 Billborad is not aligned to view

Posted by WiredCat on 28 April 2016 - 07:22 AM

lol,

 

you are picking wrong matrix, and getting wrong vector,

 

 

how is

glGetFloatv(GL_PROJECTION_MATRIX, @Matrix);
Right:= Vectorize(Matrix[0,0], Matrix[0,1], Matrix[0,2]);
Up:=    Vectorize(Matrix[1,0], Matrix[1,1], Matrix[1,2]);

equal to

double m_PickInfo_ModelView[16];// of ;
 
  t3dpoint<float> Pos;
glGetDoublev(GL_MODELVIEW_MATRIX, m_PickInfo_ModelView);
 
BillboardX.x = m_PickInfo_ModelView[0];
BillboardX.y = m_PickInfo_ModelView[4];
BillboardX.z = m_PickInfo_ModelView[8];
 
 
BillboardY.x = m_PickInfo_ModelView[1];
BillboardY.y = m_PickInfo_ModelView[5];
BillboardY.z = m_PickInfo_ModelView[9];

to be more specific

glGetFloatv(GL_PROJECTION_MATRIX, @Matrix); and glGetDoublev(GL_MODELVIEW_MATRIX, m_PickInfo_ModelView);

 

 

 

after that you will have worldspace vectors (up, right) so you: LoadIdenity then setupcamera, and draw your object (defining position of billboard and its size)




#5288112 how much can i depend on ram od current handled deviced specially andrid devices

Posted by WiredCat on 22 April 2016 - 04:09 AM

modern +1gb

 

you dont need to worry at all




#5287924 KitKat 4.4 writing to external SD etc.

Posted by WiredCat on 21 April 2016 - 03:06 AM

I dont use any fancy android local storage things, i need a clear way to write, read into internal/external memory as user chooses on which he wants to install it. Problem is kiktak (android 4.4) doesnt allow third party apps to write to external sd cards (and maybe to internal too) so what opportunities do i have?




#5287185 GLSL optimization. What is faster?

Posted by WiredCat on 16 April 2016 - 08:09 AM

For element i of the return value, 0.0 is returned if x[i] < edge[i], and 1.0 is returned otherwise.

 

 

 

Parameters

edge

Specifies the location of the edge of the step function.

x

Specify the value to be used to generate the step function.

 

 

 

 

genType step( genType edge,  

genType x);
 

 

 

 

 

now consider this

 

template <class T> T Max(T a, T b) { return (a > b ? a : b); } as an if if thats faster than normal if then we can debate on the thing, anyway if we dig in shit we end up with times for each gpu.

 

second thing seems to have more instructions than first one. since  i just converten it to asm on the flow i am not 100% sure but it seems so, fpu will do more work , and in the second line you hgave 3 ifs and on first only 2, we could rant about optimization that goes through glsl and end up that calculations (* /) are faster, but you don't always have  division in first line. someone more experienced should reply to that, but i thing for small scene without much data to process second should be faster than first one wheres first is faster for complicated scenes. , but yet not always, and again to answer the question there should be a specialist that knows how glsl optimization is done.,  thus this can vary on different gpus/cpus, and a mystery for 2016: if elses werent invented to screw the performance.




#5282420 What's wrong with my Depth Texture ?

Posted by WiredCat on 21 March 2016 - 02:14 PM

to use depth buffer in FBO you need to attach renderbuffer to it (part of code is for es 2.0 so i use depth componenet 16)

 

code creates fbo texture, then fbo object then rbo object (its a part of shadowmapping algo i use)


glGenTextures(1, &SHADOW_DEPTH_TEX);
glBindTexture(GL_TEXTURE_2D, SHADOW_DEPTH_TEX);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, RENDER_BUFF_W, RENDER_BUFF_H, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);



glGenFramebuffers(1, &SHADOW_FBO1);
glGenRenderbuffers(1, &SHADOW_RBO1);
glBindRenderbuffer(GL_RENDERBUFFER, SHADOW_RBO1);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, RENDER_BUFF_W, RENDER_BUFF_H);
glBindFramebuffer(GL_FRAMEBUFFER, SHADOW_FBO1);
glBindTexture(GL_TEXTURE_2D, SHADOW_DEPTH_TEX);
glFramebufferRenderbuffer(GL_FRAMEBUFFER,
                          GL_DEPTH_ATTACHMENT,
                          GL_RENDERBUFFER,
						  SHADOW_RBO1);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, SHADOW_DEPTH_TEX, 0);



#5278477 Triangle Strip and Perlin Noise.

Posted by WiredCat on 27 February 2016 - 04:38 PM

generate perlin noise texture. lets say each frame you move the offset (the pixel you read from that texture ) by vec2(acutal_pixel + 1, 0.0);

 

since its perlin noise you should have a smooth move from one pixel to another. now imagine you have a 256 length tri strip ribbon. (and your texture is 256x256 now y dimension on texture reponds to the vertex from the start of the ribbon so vertex at center of the ribbon will read perlintex texel on vec2(time, length(ribbon_start, vertex_pos) / 256.0);

if you define your texture as being repeated you dont need to zero time if it exceeds (1 or 256) this will give you demanded shape that is changed over time. now the thing is

you do that in vertex shader (you read the texel from perlin texture) and move your vertex by perlin tex value * some factor since its from 0..1




#5277937 how do i use printf to display an int?

Posted by WiredCat on 24 February 2016 - 01:12 PM

thanks






PARTNERS