Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 09 Apr 2011
Offline Last Active Today, 04:30 AM

#5316305 GLSL, Blending with Framebuffer Fragments via Shader?

Posted by on 23 October 2016 - 05:20 AM

+ in modern opengl theres possibility to switch between render tagets COLOR0 COLOR1 something like that you can read and write in one fragment shader to it,







additionally you could just render first scene to texture and then blend that texture with anything you want in fragment shader

#5313566 Amd openGL driver crashes

Posted by on 02 October 2016 - 02:34 AM

try to stop using shaders on rendering pass, then disable all framebuffers, shaders, 


then using my code:

some global 
TShaderObject * pplight_shader;

reloading_shaders = true;
disable all

delete pplight_shader;
pplight_shader = 0;

 pplight_shader = new TShaderObject();

reloading_shaders = false;

then you switch back rendering state to use shaders (try to stop using shaders on rendering pass,)


its a fkn simple bool that you use during render pass like if(!reloading_shaders) DrawMyScene();


heres the code with destructor



sinmce i see i dont have completedestructor i read your code and see:


GLint status;
    glGetProgramiv(program->Name, GL_LINK_STATUS, &status);
    if (status == GL_FALSE) {
        char *errorMsg = GetCompileError(program->Name, glGetProgramInfoLog, Temporary(game->Memory->System));
        DebugText(game, 5, errorMsg);
        return false;


shouldnt be there





this line is a whole bunch of crap


B32 CompileShaderProgram(Game *game, shader_program *program)



    for (U32 i=0; i<program->len; ++i)
        U32 Name = (U64)program->shaders[i]->Data;
        glAttachShader(program->Name, Name);

    const GLchar *fv[] = {"gl_Position"};
    glTransformFeedbackVaryings(program->Name, 1, fv, GL_INTERLEAVED_ATTRIBS);



//you hurt here amd feelings


why you deattach shader while attempting to load it
    for (U32 i=0; i<program->len; ++i) {
        U32 Name = (U64)program->shaders[i]->Data;
        DebugLog(game, LogType_Render, "Detaching to %d shader %d", program->Name, Name);
        glDetachShader(program->Name, Name);
        glDeleteShader(Name); N/C
    GLint status;
    glGetProgramiv(program->Name, GL_LINK_STATUS, &status);
    if (status == GL_FALSE) {
        char *errorMsg = GetCompileError(program->Name, glGetProgramInfoLog, Temporary(game->Memory->System));
        DebugText(game, 5, errorMsg);
        return false;
    } else {
        return true;




withm my code you need to add another variation since there is no shader deattaching you simply deattach them while loading or or deattaching and deleting when its initialized anyway tho read some kind of shader loading tutorial

#5304497 Make This Motion Fps-Independent?

Posted by on 07 August 2016 - 10:15 AM

to get even smoother movement use some high precision timer, or use average of times between two frames, as delta time.

#5304308 Diretcx Rotation Matrix Problem

Posted by on 06 August 2016 - 02:16 AM

^This guy above!

#5304187 Diretcx Rotation Matrix Problem

Posted by on 05 August 2016 - 07:00 AM

just to be sure, are you using the same multiplication order in shaders (both ogl and dx)?


you should use one order for both.


you could also add shaders here.


in other words post your shader code here (ogl and dx)


and youse one matrix notation for both dx and ogl

#5304175 String To Char* :(

Posted by on 05 August 2016 - 06:22 AM



That's not enough space to store the string and a terminating zero.



Just got that error, luckily you mentioned that.


a bucket of kittens for you :P



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

Posted by on 26 July 2016 - 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 on 26 July 2016 - 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 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()




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
        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 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 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 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

//  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
 // 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 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

		initialized = false;
		font_color = vec3(0.0, 1.0, 0.0);

	glDeleteBuffers(1, &alphabet_vbuffer);


AnsiString chartable;
TFontChar * Alphabet;
TShaderObject * FONT_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
CAN_LOG = true;
		FONT_SHADER = new TShaderObject();


		FONT_EVENT_SHADER = new TShaderObject();


		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].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);
		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)


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


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

		glBindBuffer(GL_ARRAY_BUFFER, 0);


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;
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 on 21 May 2016 - 01:18 PM


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 on 28 April 2016 - 07:22 AM



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)