layout,glsl,vbo , glsl layout with glvertexattribpointer issues

glsl layout with glvertexattribpointer issues


Tag: layout,glsl,vbo

So I have a working program that displays a terrain mesh generated from a height map. I want to use the layout qualifier to declare the vertex attributes now, but I am having issues. When I just use the built in gl_Normal for my normals, everything works fine. When I use a normal declared with the layout qualifier, it does not work. The vertices display just fine regardless. I'm not sure as to what I'm doing wrong here.

Here is the generation of the buffers:

glGenBuffers(1, &TerrainPVBO);
glBindBuffer(GL_ARRAY_BUFFER, TerrainPVBO);
glBufferData(GL_ARRAY_BUFFER, Terrains[IID].Points.size() * sizeof(vec3f), &Terrains[IID].Points[0], GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);

glGenBuffers(1, &TerrainNVBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, Terrains[IID].Normals.size() * sizeof(vec3f), &Terrains[IID].Normals[0], GL_STATIC_DRAW);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);

Then down in my rendering function:

glPatchParameteri(GL_PATCH_VERTICES, 3);
glDrawElements(GL_PATCHES, Terrains[IID].Index.size(),  GL_UNSIGNED_INT, 0);

If I do not use The VertexAttribArray/Pointer, and I use glVertexPointer/glNormalPointer in the drawing function (with gl_Normal/gl_Vertex in the shader), everything works fine.

This is the shader, if that helps at all:

#version 420

uniform mat3 NormalMatrix;

layout (location = 0) in vec4 vertex;
layout (location = 1) in vec3 normal;

out gl_PerVertex{
vec4 gl_Position;

out vec3 normalTCS;

void main()
gl_Position = vertex;
normalTCS = NormalMatrix * normal;

I'm sure I'm doing something stupid here, but I find this process a bit confusing. Any help would be greatly appreciated!


I'm not really sure what your isse is, but using GL_ELEMENT_ARRAY_BUFFER for your normals is not going to work. The glVertexAttribPointer() calls will always reference the currently bound GL_ARRAY_BUFFER, so you set up your noramls to be identical to your positions.

However, glNormalPointer() works the same way, so it is toally unclear to me how this could have worked before.


Add block to all CMS Pages with certain URL Key

I'm trying to discover whether this is possible or not. We have a series of CMS pages that represent our library. So the URL keys for these pages are something like: library/ library/top-ten library/five-questions library/faq etc... The powers that be want to add a static block that will appear only...

Custom TextView with icon

I need to obtain some TextView with a custom icon on them, such as these ones: but I've only been able to do this: my 3 TextView: <LinearLayout android:id="@+id/info" android:layout_marginTop="80dp" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerHorizontal="true" android:orientation="horizontal" android:layout_marginEnd="16dp" android:layout_marginRight="16dp" android:layout_marginLeft="16dp" android:layout_marginStart="16dp"> <TextView android:id="@+id/info_totali"...

How to make Search Dialog size of a toolbar

So I learned how to make Search dialog with this tutorial but it doesn't look pretty and I'm looking for proper way to fix it. As you can see search widget doesn't cover fully the toolbar and I think making it shorter by using constant dp values is not a...

Passing grayscale OpenCV image to an OpenGL texture

I want to use a grayscale image generated in OpenCV in a GLSL shader. Based on the question on OpenCV image loading for OpenGL Texture, I've managed to come up with the code that passes RGB image to the shader: cv::Mat image; // ...acquire and process image somehow... //create and...

A way to adapt the position of items in an android layout

I am currently work on an Android project, I have to show several check-box, now they are in a Relative Layout and all are positioned to their left neighbor. So in landscape, I have a line of check-box, the problem is if I switch in Portrait the line is cut,...

How to use custom css file for layout of a module in Yii2

I am using basic pack of Yii2. I created a module named Admin and I want this module has it own layout but i don't know where to put all its css files. Then, how to include them in layout.php. My dirs like this: basic -- module -- admin --...

Should Meshes with and without Skeleton use different Shaders?

Should Meshes with and without Skeleton use different Shaders? Background: Right now my shader is constructed to handle meshes with skeletons. Each vertex takes 3 bone IDs, with respective bone weight. This works well for models with skeletons that I wish to animate, but I feel that it is a...

Modern webdesign and effects?

I found this template: Now I Was wondering, when I scroll down, the navigation resizes und stays fixed, how can I do this. And when i resize the browser, the boxes in the content area are resizing and reanranging as well, how can I do that? Thanks in advance...

How to create latitudinal (horizontal) contour lines in GLSL?

I'm aiming for this effect: (horizontal-only contour lines): I did find this example, however it creates horizontal and vertical contour lines. I can't quite wrap my head around how the call to fwidth() is generating the lines. uniform float gsize;//size of the grid uniform float gwidth;//grid lines'width in pixels varying...

CSS 3 Column Layout Collapses Under Large Screen Width

I have the following section of code for by CSS 3-Column Layout. However under a very large screen width, the first column collapses (around 2000px). I added the code for the navigation, as the links could be impacting the display of the columns. CSS and HTML #container { width: 75%;...

Android Google Map in FragmentDialog being overlayed by the Dialog's own gray overlay

I just migrated a MapView from an Activity's layout to a DialogFragment. It was a pretty painless migration: A button on the activity launches the dialog, setting the LatLng the map requires: case fragmentManager = getSupportFragmentManager(); DirectionsMapDialogFragment mapDialogFragment = new DirectionsMapDialogFragment(); mapDialogFragment.setLatLng(mLatLng); mapDialogFragment.setRetainInstance(false);, "fragmentName"); break; In the...

An activity with two listviews in android

MainAcitivity public class MainActivity extends Activity { ListView list, listYear; String[] web = { "Google Plus", "Twitter", "Windows", "Bing", "Itunes", "Wordpress", "Drupal" } ; String[] year = { "2012", "2013", "2014", "2015", "2016", "2017", "2018" } ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); list=(ListView)findViewById(; list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, web));...

Plug-in: error

when I'm trying to add a Toggle Button I get an error, would you please help me here? I added a text.xml as a layout and I'm filling it. and the description is: java.lang.ArrayIndexOutOfBoundsException: -1 at android.view.ShadowPainter.createDropShadow( at android.view.ShadowPainter.createDropShadow( at android.view.ViewGroup_Delegate.getPathShadow( at android.view.ViewGroup_Delegate.drawShadow( at...

Dynamically Resizing Controls on Windows Forms

I has a winform which can be resize. I has 4 chart control in the form and sit side by side. When the form is in maximum size, the layout of each chart control is run out. I try to set the anchor style but i got no luck. How...

Modern GLSL ( opengl 3+ ) : Implementing phong effect correctly;

I am implementing a basic phong lighting GLSL shader; I have looked up some things on the internet, and found that the phong effect was created by adding an ambient, diffuse, and specular layer on the object (see image below, from tom dalling's site); problem is I have seen a...

Why these ImageButtons(delete and update) are overlaying

this .xml will be the layout of the item in the RecycleView list, but the last two Buttons are overlaying <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#Ffffff" android:baselineAligned="false" android:weightSum="1"> <LinearLayout android:id="@+id/thumbnail" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip"...

How can I render an infinite 2D grid in GLSL?

Ideally, what I'd like to do is draw a single quad and have GLSL handle the creation of the actual gridlines. In my attempt so far the vertex shader: #version 400 layout (location = 0) in vec4 in_position; layout (location = 2) in vec3 in_UV; uniform mat4 model; uniform mat4...

GLSL - program link error: Slot 0 unavailable from layout location request

I'm trying to draw a textured quad copying some code from a tutorial but I'm afraid there is a problem with the shaders. Both the vertex shader and the fragment shader compilation works, but when linking the program I get the error: ERROR: Active attribute aliasing. Slot 0 unavailable for...

Error Parsing XML: not well formed (invalid token)

I'm receiving the following message when compiling my android project: Error Parsing XML: Not well-formed (Invalid token) This is the XML layout file where the error is supposed to be: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="0.5"...

Overlaying a transparent color over a Texture with GLSL

I have an image that I am loading using the Slick library, and the image renders fine without my shader active. When I use my shader to overlay a transparent color over the image the entire image is replaced by the transparent color. without the shader With the shader Vertex...

Inline block challenges and suggestions for the layout

I keep reading articles that floats are outdated and that using inline-block solves problems such as having to use clearfix and a few more. These articles go on to justify inline-block by showing the same example: three squares that are aligned middle. In trying to use inline-block to create a...

Border some cells in table via CSS

In a very basic table I would like to put a border around some specific cells. I created for instance this table: <?php echo '<link rel="stylesheet" type="text/css" href="style1tt.css">'; echo '<table>'; echo '<tr> <th>name</th> <th>score</th> <th>position</th></tr>'; echo '<tr> <td>Bart</td> <td>189</td> <td>2</td></tr>'; echo '<tr> <td>Shirley</td> <td>211</td> <td>1</td></tr>';...

UICollectionView layout issue on iphone 5

I have a problem with my UICollectionView, I have 3 columns and everything works fine instead of iphone 5 and 4. In iphone 6 my collectionview looks that (width in cell): Iphone 5 with cells: The problem is, when in last row, I have 2 cells, and it looks like...

How to increase the indent size in (Cloud9)

In my cloud9 editor, I somehow have for some files that my indent is 3 characters and for others 7. Is there a way to harmonize this and have the same indent everywhere? Is there perhaps also an auto-indent? Example of indent with 3 characters: function indent3() { // code...

How to put a layout below other layout in Android

I have this code: RelativeLayout frame = new RelativeLayout(activity); RelativeLayout layout = new RelativeLayout(this); RelativeLayout.LayoutParams dateArea = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, 90); dateArea.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); DisplayMetrics displayMetrics = this.getResources().getDisplayMetrics(); int height = displayMetrics.heightPixels; RelativeLayout mapLayout = new RelativeLayout(this); RelativeLayout.LayoutParams mapParam = new RelativeLayout.LayoutParams(...

OpenGL GLSL: How to implement the concept of gradient map in photoshop using fragment shader?

This may be not the perfect question for stackoverflow but I have asked this in graphicdesign network of stackexchange but did not get any answer so posting it here. I am trying to implement gradient map of Photoshop programmatically using glsl fragment shader. Consider below shown gradient map where all...

What's the layouts folder for in Rails?

I understand that .html.erb files go within app/views or its subfolders. But what is the app/views/layouts folder in particular for in Rails?

Change extends(layout) dynamically in laravel 5

I have been trying to change layout dynamically in laravel by just passing a variable in @extends('default1.master') to $var = default2 @extends('$var.master') possibly @extends($var.'.master') tried a lot but unable to find a solution all I get is error in my syntax or view not found....

Why declaring @+id is allowed in other than id attributes

So lastly I have had to rebuild not my XML layout file for android app. And I saw constructions like <RelativeLayout xmlns:android="" android:layout_width="fill_parent" android:layout_height="wrap_content"> <LinearLayout android:id="@+id/rev_main" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/rev_arrow"> <!-- some stuff in here --> </LinearLayout> <ImageView android:id="@+id/rev_arrow"...

Eclipse Layout: static instead of relative values?

I have a layout with two Buttons. One button is in the Center of the left half, and the other button is in the Center of the right side. But I use relative values (left="60dp" etc.). How can I have the same result with static values? Because I don't want...

Where to place and files in project?

I'm very new to Android studio and I'm currently following a tutorial that implements a sliding tab layout for an application. The tutorial says to put and in our project, but doesn't say exactly where. For now, I just put declared them as two classes and put them...

Allow absolutely positioned child to render outside parent with overflow: hidden

How to allow for absolutely positioned element to disobey it's ancestor overflow: hidden and render outside it? The situation is complicated by the fact that there is a position: relative on the element between them in the ancestor hierarchy. Here's a pen. In this situation how to allow red inner...

How to aligning textviews on the left and right side of a linearlayout

According to below codes <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical|center_horizontal" android:layout_marginTop="15dip"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="نوع" android:gravity="left" android:layout_weight="1" android:id="@+id/txt_type" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="تاریخ:...

Ambient and Specular lighting not working correctly in GLSL

In my lighting scene, for some reason the ambient lighting isn't working at all. The whole model is the same brightness, no matter which way it is facing. I tried getting rid of the attenuation but it still has the same results. Along with that, the specular lighting is always...

Get error in Swing java - IllegalArgumentException

Tried to put on frame some swing components. This code worked to days ago. Now it's not work, didn't nothing. Maybe somebody can tell me what it's wrong? public static void main(String[] args) { JFrame mainFrame = new JFrame(); mainFrame.setSize(500, 400); //Size of frame mainFrame.setTitle("Cinema City"); //Set title mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel...

strange behaviour with UINavigationController and autolayout top layout guide

I am using auto layout for a controller under navigation controller. For this controller, I mainly have a scroll view inside the controller's view. the alignment rule for the scroll view is top layout guide, bottom layout guide, leading aligned with super view and trailing as well. the layout is...

How to achieve the following in extjs

--Title------------------------------- | | | | | <Content> | | | |_____________________________________| How to achieve the above panel in extjs? Edit: It should look something like this:

Strange layout issue

I am using a relative layout, and this is a section taken from it: <ImageView android:id="@+id/btnLifeMinus5" android:layout_width="50dp" android:layout_height="50dp" android:background="#2a80b9" android:visibility="invisible" android:adjustViewBounds="false" android:clickable="true" android:cropToPadding="false" android:padding="0dp" android:scaleType="fitStart" android:layout_marginLeft="0dp" android:layout_marginTop="0dp" /> <ImageView android:id="@+id/btnLifePlus5" android:layout_width="50dp"...

Designing layout android

I am currently trying to create a list view which will show details about a post. For that, I have created xml file for designing the list item. This is the final look I want for my activity. So far I have succeeded dealing with the rounded corners, image buttons...

OpenGL: Defining variables in shaders

My OpenGL program, using GLSL for shaders, has a simple vertex and fragment shader (given by a tutorial). The vertex shader is: #version 330 layout (location = 0) in vec3 Position; void main() { gl_Position = vec4(0.5 * Position.x, 0.5 * Position.y, Position.z, 1.0); } And the fragment shader is:...

how do i get rows and columns dynamically in windows phone app?

In my application i need to design the seat layout arrangement in the form of rows and columns dynamically. Please any one suggest me how to get rows and columns and which view i need to use. this my xaml code <Grid x:Name="grid" Background="White"> <Button HorizontalAlignment="Stretch" Foreground="Black" Margin="23,56,268,527">Text</Button> </Grid> this...

How do you make a div only extend in one direction when the outer container size increases?

I'm trying to make a a page container with a navigation bar on the left (inside of the container). When the outer page is wider than the container, I would like just the navigation bar to extend left up to a certain size while the rest of the container's contents...

trouble with GridBagLayout and panels

So what I am trying to do is create this: I am using a gridbag layout and here is what I have so far: public class board { public static void addComponentsToPane(Container pane) { pane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); JPanel leftTop = new JPanel(); leftTop.setPreferredSize(new Dimension(251,300)); leftTop.setBackground(; c.fill...

Move textview from top to bottom

In the image above I want to move the textview containing bill microsoft under the image and the other textview. How can I do this? I have written this layout right now. < android:id="@+id/card_tracks" xmlns:android="" android:layout_width="match_parent" android:layout_height="180dp" android:layout_gravity="center" android:layout_margin="16dp" android:elevation="7dp"> <LinearLayout android:id="@+id/main_ll" android:layout_width="match_parent"...

Ext JS Dashboard Layout and maximize/minimize panels

I'm attaching a picture with the mock up that I'm trying to develop with Ext JS. I'm using a Border layout, and then a Dashboard for the central part, however I see some limitations on it: Panels in the dashboard don't have minimize or maximize button. How can I implement...

Possible to change border position based on adjacent blocks in CSS?

I'm using a flexbox layout with a few blocks that can wrap. I'd like each block to create a border dynamically depending on its position relative to adjacent blocks. For example, if it is to the right of a block, I'd like a border on its left-hand side. If it...

CSS two columns without specific widths

I am trying to port a simple two column table to use div and float. I need the feature of a table that is able to scale the width of all columns to the largest content (without taking the whole browser width), but would like the added feature of floats...

One controller uses its corresponding layout, but the other does not

My Rails project has two controllers, a SessionsController and a CustomersController. My project also has two layout views in the layouts directory, sessions.html.erb and customers.html.erb. I would like the SessionsController to render using the session.html.erb layout and the CustomersController to render using the customers.html.erb layout. I have removed all explicit...

java Swing: how to keep one component left aligned with another component centered with respect to parent

Say I have two components, A and B, in a JPanel. I want Component A to stay left aligned, while Component B does its best to stay in the middle of the panel. I mocked up the following demo (sorry for the quality, I made it in paint): What I...

Adding margins to listview

I am following a tutorial and I did not understand why exactly the margins that I applied to a list view contained within a relative layout does not affect the look when I test it on a device. However, if I put everything in a LinearLayout container it looks as...