Trying to overlay a view cone on top of a grid

Managed to get the view “cone” to appear (did not look as expected but that’s my a problem with my math) but the grid which was previously visible disappeared, someone mind helping me understand the flow of overlaying?

	init_grid( 0, 0, 0, pangle );

	do
	{
		unsigned int VBO = -1, VAO = -1, VIEWAO = -1;
		
		float currentFrame = glfwGetTime();
		deltaTime = currentFrame - lastFrame;
		lastFrame = currentFrame;
		
		// Clear the screen
		glClearColor( 0, 0, 0, 0 );
		glClear( GL_COLOR_BUFFER_BIT );
		
		// Draw Stuff
		init_grid( 0, grid[0][0], grid[0][1], pangle );
		
		glGenBuffers( 1, &VBO );
		glBindBuffer( GL_ARRAY_BUFFER, VBO );
		
		glGenVertexArrays( 1, &VAO );
		glGenVertexArrays( 1, &VIEWAO );
		
		glBindVertexArray( VAO );
		glBufferData( GL_ARRAY_BUFFER, sizeof(grid), grid, GL_STATIC_DRAW );
		glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0 );
		glEnableVertexAttribArray( 0 );
		
		glBindVertexArray( VIEWAO );
		glBufferData( GL_ARRAY_BUFFER, sizeof(view), view, GL_STATIC_DRAW );
		glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0 );
		glEnableVertexAttribArray( 0 );
		
		glUseProgram( point_program );
	
		glBindVertexArray( VAO );
		glDrawArrays( GL_POINTS, 0, POINTS );
		
		glBindVertexArray( VIEWAO );
		glDrawArrays( GL_TRIANGLES, 0, POINTS );

		// Swap buffers
		glfwSwapBuffers(window);
		glfwPollEvents();

	}
	while ( glfwWindowShouldClose(window) == 0 );

Here’s a screenshot:

@ zxuiji,
whatever you’r trying to achieve, you’r loop is faul.
You generate buffers and write data for each loop. That’s a mistake since you only has to do that once. make
glGenVertexArrays( )
glBindVertexArray( );
glBufferData( );
glVertexAttribPointer( );
part of initiation-code

I’ve just tried what you said and instead got a black screen

	init_grid( 0, 0, 0, pangle );
	
	glGenVertexArrays( 1, &GRIDAO );
	glBindVertexArray( GRIDAO );
	glBufferData( GL_ARRAY_BUFFER, sizeof(grid), grid, GL_STATIC_DRAW );
	glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0 );
	glEnableVertexAttribArray( 0 );
	
	glGenVertexArrays( 1, &VIEWAO );
	glBindVertexArray( VIEWAO );
	glBufferData( GL_ARRAY_BUFFER, sizeof(view), view, GL_STATIC_DRAW );
	glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0 );
	glEnableVertexAttribArray( 0 );

	do
	{	
		float currentFrame = glfwGetTime();
		deltaTime = currentFrame - lastFrame;
		lastFrame = currentFrame;
		
		// Clear the screen
		glClearColor( 0, 0, 0, 0 );
		glClear( GL_COLOR_BUFFER_BIT );
		
		// Draw Stuff
		init_grid( 0, grid[0][0], grid[0][1], pangle );
		
		glGenBuffers( 1, &VBO );
		glBindBuffer( GL_ARRAY_BUFFER, VBO );
	
		glUseProgram( point_program );
	
		glBindVertexArray( GRIDAO );
		glEnableVertexAttribArray( 0 );
		glDrawArrays( GL_POINTS, 0, POINTS );
		
		glBindVertexArray( VIEWAO );
		glEnableVertexAttribArray( 0 );
		glDrawArrays( GL_TRIANGLES, 0, 6 );

		// Swap buffers
		glfwSwapBuffers(window);
		glfwPollEvents();

	}
	while ( glfwWindowShouldClose(window) == 0 );

You still have some that belongs to initiation. Yuo should have initiated useProgram() before the genBuffers() anyway

Can you use glGetError() to get more detail on, where an error occurs?

Ok, now I have a static image instead of blank screen or the dynamic image I had, where should I put glGetError()?

	glUseProgram( point_program );
	
	glGenBuffers( 1, &VBO );
	glBindBuffer( GL_ARRAY_BUFFER, VBO );
	
	glGenVertexArrays( 1, &GRIDAO );
	glBindVertexArray( GRIDAO );
	glBufferData( GL_ARRAY_BUFFER, sizeof(grid), grid, GL_STATIC_DRAW );
	glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0 );
	glEnableVertexAttribArray( 0 );
	
	glGenVertexArrays( 1, &VIEWAO );
	glBindVertexArray( VIEWAO );
	glBufferData( GL_ARRAY_BUFFER, sizeof(view), view, GL_STATIC_DRAW );
	glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0 );
	glEnableVertexAttribArray( 0 );

	do
	{	
		float currentFrame = glfwGetTime();
		deltaTime = currentFrame - lastFrame;
		lastFrame = currentFrame;
		
		// Clear the screen
		glClearColor( 0, 0, 0, 0 );
		glClear( GL_COLOR_BUFFER_BIT );
		
		// Calculate Points
		init_grid( 0, grid[0][0], grid[0][1], pangle );
		
		// Draw Stuff
		glBindVertexArray( GRIDAO );
		glDrawArrays( GL_POINTS, 0, POINTS );
		
		glBindVertexArray( VIEWAO );
		glDrawArrays( GL_TRIANGLES, 0, 6 );

		// Swap buffers
		glfwSwapBuffers(window);
		glfwPollEvents();

	}
	while ( glfwWindowShouldClose(window) == 0 );

On a somewhat related note (as in same file, pertains to the view cone), do you have any experience using deltaTime type variables against small integers? As in 0 - 100, tried but no movement occurred until I upped the limit to 1000 which had the knock on effect of slowing things too far down instead.

Resolved my multiple object issue:

	glGenBuffers( 1, &VBO );
	glBindBuffer( GL_ARRAY_BUFFER, VBO );
	
	glGenVertexArrays( 1, &GRIDAO );
	glBindVertexArray( GRIDAO );
	glBufferData( GL_ARRAY_BUFFER, sizeof(grid), grid, GL_STATIC_DRAW );
	glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0 );
	
	glGenVertexArrays( 1, &VIEWAO );
	glBindVertexArray( VIEWAO );
	glBufferData( GL_ARRAY_BUFFER, sizeof(view), view, GL_STATIC_DRAW );
	glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0 );

	do
	{	
		float currentFrame = glfwGetTime();
		deltaTime = currentFrame - lastFrame;
		lastFrame = currentFrame;
		
		glUseProgram( point_program );
		
		// Clear the screen
		glClearColor( 0, 0, 0, 0 );
		glClear( GL_COLOR_BUFFER_BIT );
		
		// Calculate Points
		init_grid( 0, grid[0][0], grid[0][1], pangle );
		
		// Draw Grid
		glBindVertexArray( GRIDAO );
		glBufferData( GL_ARRAY_BUFFER, sizeof(grid), grid, GL_STATIC_DRAW );
		glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0 );
		glEnableVertexAttribArray( 0 );
		glDrawArrays( GL_POINTS, 0, POINTS );
		
		glBindVertexArray( VIEWAO );
		glBufferData( GL_ARRAY_BUFFER, sizeof(view), view, GL_STATIC_DRAW );
		glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0 );
		glEnableVertexAttribArray( 0 );
		glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );

		// Swap buffers
		glfwSwapBuffers(window);
		glfwPollEvents();

	}
	while ( glfwWindowShouldClose(window) == 0 );

Still could use help on using my deltaTime variable with a small integer of 0 to 100 though

For that integer problem of mine this is the furthest I get:

void glfwOnKey( GLFWwindow*window, int key, int scancode, int action, int mods )
{
	float move = 1.0;
	float turn = (max_angle / 8);
	
	switch ( key )
	{
		case GLFW_KEY_ESCAPE:
			if ( action == GLFW_PRESS )
				glfwSetWindowShouldClose( window, true );
			break;
		case GLFW_KEY_W:
		case GLFW_KEY_A:
		case GLFW_KEY_S:
		case GLFW_KEY_D:
			if ( mods == GLFW_MOD_SHIFT )
				move *= 2;
			else if ( mods == GLFW_MOD_CONTROL )
				move /= 2;
			break;
	}
	
	move *= deltaTime;
	turn *= deltaTime;
	
	switch ( key )
	{
		case GLFW_KEY_W: grid[0][1] += move; break;
		case GLFW_KEY_S: grid[0][1] -= move; break;
		case GLFW_KEY_A: grid[0][0] -= move; break;
		case GLFW_KEY_D: grid[0][0] += move; break;
		case GLFW_KEY_LEFT: pangle -= turn; break;
		case GLFW_KEY_RIGHT: pangle += turn; break;
	}
	
	if ( pangle >= max_angle )
		pangle = -max_angle + -(max_angle - pangle);
	else if ( pangle <= -max_angle )
		pangle = max_angle + (max_angle - pangle);
}

not without adding the code that we just moved out!
Your “static image” code is proper.

Not after static image though, I’m after a dynamic image because I’m testing math that skips raycasting and directly calculates the point looking at

I’m lost.
I cannot figure out weather you cannot express your problems properly or weather your problems are advanced stuff that I don’t know about.
I’m not trying to be condescending.

Well the point of opengl is dynamic images on screen, I thought of a method to take any angle and calculate the relative x/y axis that looking at, has potential to scale to 3d also, anyways I’m storing the angle as an integer because the method requires the modulo operator and it’s almost complete, just some fine tuning with how I use the resulting variables to work out.

This usually happens through a uniform variable in the shader. Either through a vec2 or 3 that you can add to some or all points to move them. Or, use a matrix-uniform to translate whatever you want to translate.

I’ve not dealt with matrices before and considering what I’m doing now is not the time to be diving into it, for now improper code is good enough, I can learn about matrices after I’ve completed the math I’m developing and uploaded it.

do you set the viewport somewhere. It performs a matrix operation.
If you wand to scale your model into pixels on the screen, using an orthographic projection would be a very good idea, particularly one with the same values as the viewport. It gives you (0,0) at your lower Left corner and (width,hight) on your upper right corner of the screen … this is conformable to the cursor-position you can read from the proper callback.
What are the coordinate-values of your points? … somewhere between -1 → 1 ?

I’m not dealing with specific pixels, just the normalised co-ordinates

Whatever you need this for, it certainly sounds like reverse-engineering what the viewport does.

Forgetting the matrix stuff: if you want to move the points around, you can/should use the offset vector, a uniform variable in the shader. It’s messy stuff too, I know. But I seriously doubt that wou’ll get anywhere near 3d without these things.

Not quite what I mean to do, you’re familiar with ray casting right? Where it takes steps through the map to find the first object visible to a player, well I intend to go a different route, instead first calculate the outer limits of what to draw then, while going through the objects list adjusting their positions, fill an array of what to draw in front of the player and draw that instead of the map, in other words the map will never be sent to the GFX card but instead just the small array of objects.

You’ll work with one angle-variable to controle all movement by adding it as a z-value to the points and enforce crap drawing-code to make it work.

you’r on your own, zxuiji

It’s not the z-value (I was simply saying it can be expanded on), also, I’m not enforcing crap drawing code, just using it to test my math, I’ll bring in matrices after. Right now however I need the code environment kept as simple as possible for both me and others to understand how the math effects the “view cone”, every proof of concept starts with something crap which is then improved upon once it’s seen to work as intended, as for not sending the map that’s just for de-complicating things, I’m sure it’s possible to achieve the same on the GFX card but trying to juggle multiple new concepts is a dumb idea and will lead to more failures then successes, better to start with the minimum number (in this case 2, the math and drawing anything to screen).