glTexCoordPointer problems using OpenGL ES - opengl-es

I have some problems mapping a texture to a triangle strip. I think I still don't fully understand the texture coordinates.
I have a 512x512 texture, and I'm trying to map the 320x64 part of it on a triangle strip.
Here is my code:
static const Vertex3D bg_vertex [] =
{
{ 0, 0, 0}, { 0, 64, 0}, { 64, 0, 0},
{ 64, 64, 0}, {128, 0, 0}, {128, 64, 0},
{192, 0, 0}, {192, 64, 0}, {256, 0, 0},
{256, 64, 0}, {320, 0, 0}, {320, 64, 0}
};
static const GLfloat bg_texcoords [] =
{
{1.000, 0.000}, {1.000, 0.125}, {0.875, 0.000}, {0.875, 0.125}, {0.750, 0.000}, {0.750, 0.125},
{0.625, 0.000}, {0.625, 0.125}, {0.500, 0.000}, {0.500, 0.125}, {0.375, 0.000}, {0.375, 0.125}
};
glBindTexture (GL_TEXTURE_2D, bg1Texture);
glEnable(GL_TEXTURE_2D);
glColor4f (1.0, 1.0, 1.0, 1.0);
glTexCoordPointer(2, GL_FLOAT, 0, bg_texcoords);
glVertexPointer(3, GL_FLOAT, 0, &bg_vertex);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 12);
When I run the code, it displays a distorted image of the original texture on the triangle strips.
Can someone please tell me what am I doing wrong?
Thanks

OK, it works now when I removed the extra braces from the texture coordinates:
static const GLfloat bg_texcoords [] =
{
1.000, 0.000, 1.000, 0.125, 0.875, 0.000, 0.875, 0.125, 0.750, 0.000, 0.750, 0.125,
0.625, 0.000, 0.625, 0.125, 0.500, 0.000, 0.500, 0.125, 0.375, 0.000, 0.375, 0.125
};
Now it maps the texture perfectly on the triangles

Related

Printing tchar array as unicode string rust winapi

I'm using the winapi to grab a list of the current processes running on the system, here's my code:
use winapi::um::tlhelp32::{Process32Next, Process32First, CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS, PROCESSENTRY32};
use winapi::um::winnt::HANDLE;
use winapi::um::handleapi::CloseHandle;
use std::mem::size_of;
...
fn get_processes() {
let h_process_snap: HANDLE;
// really, rust?
let mut pe32 = &mut PROCESSENTRY32{
dwSize: 0,
cntUsage: 0,
th32ProcessID: 0,
th32DefaultHeapID: 0,
th32ModuleID: 0,
cntThreads: 0,
th32ParentProcessID: 0,
pcPriClassBase: 0,
dwFlags: 0,
szExeFile: [0; 260],
};
unsafe {
h_process_snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
}
pe32.dwSize = size_of::<PROCESSENTRY32>() as u32;
unsafe {
if Process32First(h_process_snap, pe32) == 0 {
CloseHandle(h_process_snap);
println!("can't get a process snapshot");
// TODO: return
}
while Process32Next(h_process_snap, pe32) != 0 {
println!("{:?}", pe32.szExeFile);
}
}
}
...
Now I'm trying to print the actual name of the process, in C++, this can be done using cout or wcout.
When I use println!("{:?}", pe32.szExeFile);, this is what I get:
[115, 117, 112, 101, 114, 102, 52, 45, 114, 117, 115, 116, 46, 101, 120, 101, 0, 116, 46, 101, 120, 101, 0, 98, 108, 101, 83, 104, 101, 108, 108, 46, 69, 120, 112, 101, 114, 105, 101, 110, 99, 101, 115, 46, 84, 101, 120, 116, 73, 110, 112, 117, 116, 46, 73, 110, 112, 117, 116, 65, 112, 112, 46, 101, 120, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
I don't really understand how to work with this, how can I print the pe32.szExeFile as a Unicode string in rust?
see also: https://docs.rs/winapi/0.3.6/winapi/um/tlhelp32/struct.PROCESSENTRY32.html
Thanks to #IInspectable, I used the explicit Unicode versions, e.g. Process32FirstW, and from_wide to print the values in readable format:
let os_string = OsString::from_wide(&pe32.szExeFile[..]);
// ExeFile names have a lot of trailing 0's, remove them...
let exe_files: String = os_string.into_string().unwrap().replace("\u{0}", "");
println!("{:?}", exe_files);

Cythonizing function containing too many arrays

Running setup.py on the code below takes some seconds to finish; however, by increasing number of arrays to 20k, .pyd is not generated after 2 hours of running the setup on windows XP 32 bit. Should I use a specific definition for the arrays?
import numpy
import scipy.interpolate
from scipy.interpolate import interp2d
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
y = [0.1, 0.2, .3, 0.4, 0.5, 0.6, .7, 0.8, .9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9]
def interpolate(DATA,x_new,y_new):
var1 = DATA[0]
var2 = DATA[1]
f = interp2d(y,x,var1,kind='linear')
k1 = f(y_new,x_new)
f = interp2d(y,x,var2,kind='linear')
k2 = f(y_new,x_new)
return (k1[0],k2[0])
def function(condition1,condition2,param1,param2):
Data1_var1=[[6L, 5L, 8L, 8L, 9L, 3L, 2L, 1L, 1L, .7, 5.7, 4.8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [5L, 1L, 9L, 5L, 4L, 8L, 9L, 3L, 9.5, 7.2, 5.5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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0], [2L, 4L, 1L, 8L, 6L, 1L, 2L, 10L, 8.9, 7.7, 6.5, 5.6, 5L, 4.6, 4.1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [2L, 3L, 2L, 7L, 5L, 3L, 2L, 10L, 9.2, 8.1, 6.9, .1, .6, 5.1, 4.6, .2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
if condition1:
if condition2:
out = interpolate(Data1,param1,param2)
else:
out = interpolate(Data2,param1,param2)

How to replace X axis numerical values(years) with custom labels in D3.js for this example?

I am new to D3.Js, I found below example of sunburst with line chart, I was able to use it.
http://bl.ocks.org/wizicer/raw/f662a0b04425fc0f7489/
jsfiddle:Link
However, it displays only year values in X axis, but I need custom text labels such as "March 2019", April 2019" etc.
Default X axis
Is it possible to replace year values(1999, 2000, 2001 etc) as shown below with text labels?
var chart = {},
rect = {
top: 20,
right: 20,
bottom: 30,
left: 50
},
g = 500 - rect.left - rect.right,
h = 400 - rect.top - rect.bottom,
i = [1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013],
j = d3.scale.linear().range([0, g]),
k = d3.scale.linear().range([h, 0]),
bottomtick = d3
.svg
.axis()
.scale(j)
.tickValues([1999, 2004, 2009, 2013])
.tickFormat(d3.format(".0f"))
.tickPadding(10)
.tickSize(0)
.orient("bottom"),
Format of the source data
var skillsdata;
skillsdata = {
"Skills": {
"Server & WinForm": {
"Protocol": {
"Propose": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 30, 50, 50, 50],
"USSD": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60, 60, 50, 40, 30],
"UAP": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60, 70, 50, 30],
"Socket Raw": [0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 50, 50, 50, 70, 80]
},
My edit
var chart = {},
rect = {
top: 20,
right: 20,
bottom: 30,
left: 50
},
g = 500 - rect.left - rect.right,
h = 400 - rect.top - rect.bottom,
j = d3.time.scale().domain([new Date("2014-01-01"), new Date("2016-06-01")]).range([0, 850]),
k = d3.scale.linear().range([h, 0]),
bottomtick = d3
.svg
.axis()
.scale(j)
.tickFormat(d3.time.format("%B %Y"))
.tickPadding(10)
.tickSize(0)
.orient("bottom"),
lefttick = d3
.svg
.axis()
.scale(k)
.tickSize(0)
.tickPadding(10)
.tickValues([20, 40, 60, 80, 100])
.orient("left"),
The timeformats available in d3.v3 is defined here in this document: https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Formatting.md.
I have attached a snippet to show how we can achieve it, hope this is helpful! I believe you just have to do:
// tick-format:
.tickFormat(d3.time.format("%B %Y"))
//scale type
d3.time.scale()
var svg = d3.select("body")
.append("svg")
.attr("width", 900)
.attr("height", 100)
var xScale = d3.time.scale()
.domain([new Date("2014-01-01"), new Date("2016-01-01")])
.range([0, 850]);
var xAxis = d3.svg.axis()
.scale(xScale)
.tickFormat(d3.time.format("%B %Y"))
.orient("bottom");
svg.append("g").call(xAxis);
<script src="https://d3js.org/d3.v3.min.js"></script>

Obtain sub-cv::Mat from a given image such that

I have a processed an image that returns a Mat say:
[
[ 0, 0, 255, 255, 255, 0, 0, 0],
[ 0, 0, 0, 255, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 255, 255, 0],
[ 0, 0, 0, 0, 0, 255, 255, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0]
]
are there any segmentation functions that can help me isolate individually ?
if not so what would be the best approach ?
i.e. say if i do mysegment(Mat a,0) should return
[
[ 0, 0, 255, 255, 255, 0, 0, 0],
[ 0, 0, 0, 255, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0]
]
then mysegment(Mat a,1) will return
[
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 255, 255, 0],
[ 0, 0, 0, 0, 0, 255, 255, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0]
]
I consider continuous 255 pixels to be a block. Now I want to iterate over or process these blocks ... since more than one block can be formed in a matrix.
You can use contours
findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
the link to the library

3D skew transformation matrix along one coordinate axis

Is there a way to calculate the skew transformation matrix along one coordinate axis, given the skew angle, as follows
This should work for the most part for skewing an object with a transformation matrix, in particular using glMultMatrix(matrix)
matrix1[] = {
1, 0, 0, 0,
tan(a), 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
};
matrix2[] = {
1, 0, 0, 0,
0, 1, 0, 0,
tan(a), 0, 1, 0,
0, 0, 0, 1
};
matrix3[] = {
1, tan(a), 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
};
matrix4[] = {
1, 0, 0, 0,
0, 1, 0, 0,
0, tan(a), 1, 0,
0, 0, 0, 1
};
matrix5[] = {
1, 0, tan(a), 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
};
matrix6[] = {
1, 0, 0, 0,
0, 1, tan(a), 0,
0, 0, 1, 0,
0, 0, 0, 1
};

Resources