C++ :: Creating Shaders - Scaling Matrix In GLSL

Jul 22, 2013

I'm working on creating shaders to be used for displaying text in my openGL programs but am having trouble. I want to be able to scale the text but I don't want to use a uniform ( I want different strings of text to be able to be scaled differently ) so I'm using an in variable. I'm not sure how to use a VBO with a mat4 so instead i've been using a vec2 and trying to convert it to a mat4 in glsl before multiplying it with the position. The problem is that when I run my program, my text isn't scaled; it's just partially missing (the part that is there is about the same size). My vertex shader for this is:

#version 140
in vec2 Position;
in vec4 VertexColor;
in vec2 TexCoord;
in vec2 Scale;

out vec4 Color;
out vec2 UV;

[Code] ....

Also, scaling matrix should look like this:

| x, 0, 0, 0 |
| 0, y, 0, 0 |
| 0, 0, z, 0 |
| 0, 0, 0, 1 |

with z = 1 for 2d scaling, right?

View 4 Replies


ADVERTISEMENT

C :: Scaling Y Axis - Vertical Histogram

Mar 6, 2015

Scaling the yaxis on my histogram for one of my class projects. I've gotten mostly everything but stuck on scaling. I'm pretty sure it's something simple to do, but I'm having trouble, and I've tried everything to my knowledge to get it scaled from 0.1 - 1, like this:

Here is my code:

#include<stdio.h> //include all preprocessor directives
#include<Windows.h>
int main(void) {
int MAX = 0; //initialize and declare variables
int allcounts [10] = {0}; //store an array of integers for
int yaxis, xaxis = 0;

[Code] ....

I'm close, but every time I try and change my y axis in the for loop from 1 going down to 0.1, it doesn't give me a right output.

View 2 Replies View Related

C++ :: GLSL Heightmap Coloring (OpenGL)

Aug 27, 2013

I recently made a heightmap, it uses a triangle strip /row, and I try to figure out how can i color the triangles one by one. So, for example I have a color array of 9:

[0.0f,0.2f,0.6f //a triangles first vertex
0.0f,0.4f,0.3f //second vertex
0.0f,0.7f,0.2f] //third vertex

And I want to use it to color all triangles with it. My heightmap coords are in a vector:

vector<GLfloat> hmapcrds [x1,h1,z1; x2,h2,z2;...]

Like this:

c1 c2 c3 c4 c5 //row 1
c6 c7 c8 c9 c10 //row 2 coordinates

index array:c6->c1->c7->c2 ...cn->c(n-rwosize)->c(n+1)->cn->c(n-rwosize+1)

I draw my elements with a VAO and drawelements/row; (i tried drawrange but didnt work)
...
glGenVertexArrays(1,&VertArrObj);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(GLuint)*v_heightIndexes.sie(),&v_heightIndexes[0],GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER,vertexBuffer);

[Code] ....

I think it want to index my color array too, so how can i do that it only reads the 3 colors from my array, the repeat it /vertex/triangle till the end of drawing.

The shaders work fine, i changed the map to a triangle so it applied these colors, but with the map "I see only darkness before me".

with my working shader without color "in" - height coloring: [URL] ....

(I also want to do texturing per triangle.)

View 2 Replies View Related

Visual C++ :: Creating Matrix / Map For Topological Sort?

May 10, 2014

I am trying to simulate the logical circuits having NAND gates. I am reading the structure from .bench file. The structure of a circuit looks like below:

Code:
INPUT(1)
INPUT(2)
INPUT(3)
INPUT(6)
INPUT(7)
10 = NAND(1, 3)
11 = NAND(3, 6)
16 = NAND(2, 11)
19 = NAND(11, 7)
22 = NAND(10, 16)
23 = NAND(16, 19)

It can be seen that the inputs for Gate 22 are 10 and 16 which are also NAND gates. On the other hand, for gate 10, the inputs are 1 and 3 which are simple inputs. So, i need to sort the gates topologically. Although topological sort will not affect the output for this particular example but i have big circuits also in which topological sort is required. But we can use this simple example to do the topological sort.

My effort:I thought to create a map which will keep the information about the gate name and its indegree. But i am unable to proceed further.

Code:
void Circuit::topologicalSort()//topological sorting (for the mixed circuits) {
int counter = 0;
std::map<string, int> unsortTopoList; //this list keeps a track of gate name and its Indegree
for(int i=0; i<gates.size(); i++) {

[code].....

View 4 Replies View Related

C++ :: Shaders Running Slower Than Fixed Pipeline

Feb 3, 2014

While testing some simple examples with glDrawArrays I noticed switching it to shaders can cut my frame rate by over half (from 600- 300). I know I am using a bunch of deprecated code in GLSL right now but I don't expect it to cause that much of an fps drop. I would say it was just my intel graphics chip but if the FFP can handle it I see no reason shaders can't.

--Windows 7 Premum 64-bit
--Intel Core i3 540
--Intel HD Graphics

//Sending 10,000 quads with GLfloats (So Vertices vector has 80,000 elements, currently no indexing).
//Vertices allocated earlier in code, before main game loop

glBindBuffer(GL_ARRAY_BUFFER, vbo);
glEnableClientState(GL_VERTEX_ARRAY );

glVertexPointer(2, GL_FLOAT, 0, 0);
glDrawArrays(GL_QUADS, 0, Vertices.size() / 2);

[Code] .....

The highest Opengl version I can run is 2.1 so 120 in shaders. I know this is a fairly pointless test right now but it is still surprising to see, anything obvious I am missing?

View 19 Replies View Related

C++ :: Using OOP To Implement Matrix Class That Provide Basic Matrix Operations

Mar 27, 2013

i want to know how i can solve this question? do i need to create a class or write the program codes.

View 12 Replies View Related

C++ :: Accept Matrix As Argument And Display Its Multiplication Matrix

Jun 1, 2014

I just want to know the code of the program: Write code to accept matrix as aurgument and display its multiplication matrix which return its multiplication matrix.

View 1 Replies View Related

C/C++ :: Assign A Matrix To Submatrix Of A Bigger Matrix?

Feb 27, 2012

I want to assign a matrix to submatrix of a bigger matrix.

ublas::matrix<int> A(8,5);
ublas::matrix<int> B(2,5);
for(size_t i=0;i<A.size1();++i)
for(size_t j=0;j<A.size2();++j)
        A(i,j)=i*A.size2()+j+1;
for(size_t i=0;i<B.size1();++i)
    for(size_t j=0;j<B.size2();++j)
        B(i,j)=i*B.size2()+j+5;
ublas::matrix_range<ublas::matrix<int> > a(A,ublas::range(0,2),ublas::range(0,5));
a=B;  

and it works.

but if the matrix is compressed_matrix type, there's something with it. the error log as below:

Check failed in file boost_1_48_0/boost/numeric/ublas/detail/matrix_assign.hpp at line 1078:
detail::expression_type_check (m, cm)
terminate called after throwing an instance of 'boost::numeric::ublas::external_logic'
what(): external logic
Aborted

I'm not sure this is a bug or not.

View 2 Replies View Related

C++ :: Find Matrix P For A Square Matrix A

May 25, 2014

I have to prepare a project. But I don t know how can I do this. Program will find a matrix P for a square matrix A such that P^-1 A P ....

View 15 Replies View Related

C++ :: How To Convert Compact Form Of Matrix Into Matrix Form

Oct 4, 2014

3 3
2 1 3 2 3
1 0 2
1 2 6

First line shows row and column number

First index of the second line tells the number of non-zero entries of the first row and second index tell the column number where the non zero entry is placed

for 1st row of matrix:

non-zero entries=2
column number=1
non-zero entry=3
column number=2
non-zero entry=2

covert this in the given form
0 3 3
2 0 0
0 0 6

View 1 Replies View Related

C++ :: Get Matrix Indexes From The Value

Oct 17, 2013

I have a 3x3x3 matrix with values hanging from 1 to 27.

The order is this: Code: m[0][0][0] = 1;
m[0][0][1] = 2;
m[0][0][2] = 3;
m[0][1][0] = 4;
m[0][1][1] = 5;
m[0][1][2] = 6;
.
.
.
m[1][0][0] = 10;
m[1][0][1] = 11;
m[1][0][2] = 12;
.
.
.
m[2][2][0] = 25;
m[2][2][1] = 26;
m[2][2][2] = 27;

Is there an easy way to compute the indexes given the value? For example, I know that the first index can be found by dividing the value by 9.0: Code: const int firstIndex = ceil(value / 9.0) - 1; What about the second and the third indexes? I couldn't find a pattern in the numbers, and I didn't want to iterate through the matrix (the indexes will be calculated many times).

The other option is to create arrays where the values will be indexes and the matrix indexes will be the values. I'm not sure if it is the best way though

View 6 Replies View Related

C :: Getting Error On Matrix

Mar 6, 2015

I've a code and it works on my linux laptop; however it doesnt work on a matrix server. Im getting error Code: file.c: In function CondCheck:file.c:40:3: warning: this decimal constant is unsigned only in ISO C90 [enabled by default] The code of the programme

Code:

#include <stdio.h>
#include <string.h>
#include <math.h>
/*DECIMAL TO BINARY CONVERTER*/
int BinaryConverter (int bina)
}

[code]....

View 1 Replies View Related

C++ :: How To Print Matrix

Jan 27, 2015

I wants to print matrix such that Consider that original matrix look like following

1 2 3
4 5 6
7 8 9

Now I want to print like following

7 8 9
4 5 6
1 2 3

we can use only two for loops.

View 1 Replies View Related

C++ :: Inserting A Row Into A Matrix?

May 1, 2013

I'm writing a function that inserts a row into a matrix and deletes the last row.

But I'm having trouble. What do I need to add to this function:

View 1 Replies View Related

C/C++ :: Add Row To Irregular Matrix?

Apr 7, 2013

//matrix :

12 5 35 35 35 65 170
48 15 190 85 27 27 24
100 315 119 600 116 129 70
88 110 145 90 90 90 90
77 85 130 55 210 122 200  

// the row :

152 152 149 155 170  

// matrix after adding the previous row :

12 5 35 35 35 65 170
48 15 190 85 27 27 24
100 315 119 600 116 129 70
88 110 145 90 90 90 90
77 85 130 55 210 122 200
152 152 149 155 170  

We use the pointer.

- Can I print out the irregular matrix?

View 4 Replies View Related

C++ :: Matrix Multiplication Using Pointers

Feb 15, 2014

Code:
#include<stdio.h>
#include<conio.h>
void main()

[Code] .....

This program on running returns an error of "ILLEGAL USE OF POINTER".

View 4 Replies View Related

C++ :: Multiplying Matrix Using Algorithm

Jun 3, 2013

Trying to multiply to matrixes using the following algorithm,

Code:
ABrec(A,B)
n=A.rows; //n must be multiple of 2
C is a new n*n matrix.
if(n==1)
C[0][0]=A[0][0]*B[0][0];

[Code] ....

but the code doesn't work !!!

View 4 Replies View Related

C++ :: Display Matrix Of Multiples Of 4

Feb 25, 2013

Write a c++ program to display a matrix of multiples of 4 from 1 upto 30 .....

View 1 Replies View Related

C :: Adding Two Matrix Using Malloc

Mar 3, 2015

This is my code without malloc. I need to change the array size so there is no max size for each matrix. I must dynamically allocate space for all arrays used. So I need to use malloc to create my arrays. So I cant use int A[rows][cols].

Code:

/* This program asks the user for 2 matrices called A and B, as integers, and displays their sum, C. The max dimension of each matrix is 100. */
#include<stdio.h>
// Construct function
void construct()
{
int m, n, i, j;// Variables
int first[100][100], second[100][100], sum[100][100];// Matrices variables

[Code]...

Im having a hard time understanding/using malloc. Should first, second, and sum be single pointers or double? How do I scan the matrix correctly? And how do I add them properly? Do I have to change my for loops?

Code:

/* This program asks the user for 2 matrices called A and B, as integers, and displays their sum, C. The max dimension of each matrix is 100. */
#include <stdio.h>
#include <stdlib.h>
// Construct function
void construct()

[Code]...

View 3 Replies View Related

C :: Matrix Multiplication Using Pointers

Feb 17, 2014

Code:
#include<stdio.h> Code: #include<conio.h>
void main() {
int *a[2][2],*b[2][2],*c[2][2],i,j,k;
Printf("
ENTER a MATRIX ELEMENTS

[Code] .....

View 4 Replies View Related

C :: Sending Matrix Over UDP Socket

May 18, 2014

I want to apply program to send matrix from client and server ,and return back a processed matrix ..

How I can do it using UDP ,it was easy to use tcp for that!?

View 3 Replies View Related

C :: Array And Matrix Check

Sep 24, 2013

1. Input an dimension and elements of an array from the keyboard. Count the odd elements of an array and that number join to variable K, then sort the last K elements in decreasing order.

Code:
#include <stdio.h>
main ()
{
int A[100], i, n, j, K = 0;
printf ("Type in the dimension of an array:
");
scanf ("%d", &n);

[Code]....

View 7 Replies View Related

C :: All Paths Between Two Nodes In Matrix

Jun 9, 2014

I have a adjacency matrix. (router adjacency matrix in network). The result should be the router ID.I mean, print all the possible paths from source router to target router(ROUTER id>> 1 - 2 - 3 - 4 so there are four one router). I get the error in the output.)

Code:
#include<stdio.h>
#include<conio.h>
/* graph: Pointer to the starting of mXn matrix
i, j: Current position of the robot (For the first call use 0,0)
m, n: Dimentions of given the matrix
pi: Next index to be filed in path array

[Code] .....

View 3 Replies View Related

C :: Find Minimum Value In Given Matrix M

Jun 16, 2013

The method doesn't work properly, the point of the code is to tell the minimum value in the given matrix "m", it's supposed to take the first value of the matrix store it in min_ and then compare it to every value of the matrix, if the value stored in min_ is bigger than the current value in the loop then it's stored as the new min_ and at the end it's supposed to print that minimum...

Code:
#include <stdio.h>
#include <stdlib.h>
#define SIZE 3
void minimum (int mat[SIZE][SIZE]){
int r,c;
int min_;
printf("

[Code] ......

View 5 Replies View Related

C++ :: Dynamic Size Of A Matrix

Apr 24, 2013

My purpose is to fill a matrix with random numbers. As you can see in the code, I defined a matrix called sim_matrix (which should be filled), but the dimensions of such matrix is given by the parameters that we introduce in the constructor. Because we don't know the size of such matrix until we give these parameters through the constructor. I'd like to know how to declare such matrix, or how to modify the size,...

The header of my file MonteCarlo.h is:

/* MonteCarlo.h */

#ifndef MONTECARLO_H_
#define MONTECARLO_H_
using namespace std;
class MonteCarlo {
public:
MonteCarlo(int n_paths, int n_simulations);

[Code] ......

View 2 Replies View Related

C++ :: Function Outputs Different Matrix

Jun 25, 2013

It is getting more and more annoying, everytime i progress the next hurdle is just bigger. The problem is i want to calculate inverse of a matrix but using .inv gives a matrix full of -1.#QNAN values so i decided to write one my self

a function which returns the inverse matrix but something strange happens.

when i debug through the function code it works well and check the matrix that will be returned and the elements are correct.

when the function is called and output matrix is resulted. the element of the matrix is different.

matrix = inversemat(matrx)
inside function, invmat= 3 1 2, 3 5 1, 8 1 2
outside the function matrix = -9.1249e+61 wtf.

here is the code

int main() {
double matrx[3][3]={{1,2,3},{0,1,4},{5,6,0}};
Mat matrx1(3,3,CV_64F,matrx);
Mat inmat;
inmat=inversemat(matrx1);

[Code] ...

invmat elements are correct, as for inmat the elements are too small -9.212412e+61

What is going on, when the matrix is returned.

View 19 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved