GridPane takes much more space than required - javafx

I have a GridPane setup:
GridPane pane = new GridPane();
// 3 columns, which percent widths are 40%, 27% and 33%, respectively
setColumnPercents(pane, 40, 27, 33);
// 4 rows, each percent height is 25%
setRowPercents(pane, 25, 25, 25, 25);
pane.setHgap(10);
pane.setVgap(10);
// getView() returns a StackPane
// The 4 arguments of getView() specifies the stack pane's
// prefWidth, prefHeight, minWidth and minHeight
pane.add(setGridGrow(getView(196, 112, 106, 112)), 0, 0, 1, 4);
pane.add(setGridGrow(getView(131, 104, 57, 104)), 1, 0, 1, 3);
pane.add(setGridGrow(getView(93, 26, 42, 26)), 1, 3);
pane.add(setGridGrow(getView(185, 72, 74, 72)), 2, 0, 1, 2);
pane.add(setGridGrow(getView(140, 76, 55, 76)), 2, 2, 1, 2);
return pane;
In this example, the first column contains 1 node spanning 4 rows, its prefHeight and minHeight both set to 112, the grid height required to contain this node is (112 - (3 * 10)) / 4 = 27.3, the second column contains 2 nodes, the node above spans 3 rows, another grid height can be calculated based on its height: (104 - 2 * 10) / 3 = 28, the node below does not span, so its respective grid height is 26, for the two nodes in the third column, each spans 2 rows, 2 more grid height can be calculated: (72 - 10) / 2 = 31 and (76 - 10) / 2 = 33. Putting these together, a minimal grid height 33 is big enough for the gridpane to contain all its children, so the minimal total height of the pane is 33 * 4 + 3 * 10 = 162.
However, when I run this code, the total height of the gridpane turns up to be 298, way bigger than the expected minimal height.
What's more, if the row span of the first node is changed to 3, the result gridpane height (250) is smaller, which seems unreasonable to me because the size of the node does not change, while it is required to be fit into a smaller portion of the gridpane.
// pane.add(setGridGrow(getView(196, 112, 106, 112)), 0, 0, 1, 4);
pane.add(setGridGrow(getView(196, 112, 106, 112)), 0, 0, 1, 3);
What I expect is that the height of the gridpane does not exceeds the minimal height required for all it's children too much, and if the row span of the first node is changed from 4 to 3, the result gridpane height being bigger or unchanged, not smaller. Otherwise my UI layout would break unpredictably. Is there any way I can achieve these?
The full code is pasted below. I have ran it on JavaFX 8, 11 (JDK=11) and 16 (JDK=11), Windows 10, got consistent results.
package com.example.javafxlayoutdemo;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import java.util.Objects;
public class GridPaneLayoutDemo extends Application {
#Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setScene(new Scene(getRoot()));
primaryStage.show();
}
private GridPane getRoot() {
GridPane pane = new GridPane();
// 3 columns, which percent widths are 40%, 27% and 33%, respectively
setColumnPercents(pane, 40, 27, 33);
// 4 rows, each percent height is 25%
setRowPercents(pane, 25, 25, 25, 25);
pane.setHgap(10);
pane.setVgap(10);
// getView() returns a StackPane
// The 4 arguments of getView() specifies the stack pane's
// prefWidth, prefHeight, minWidth and minHeight
pane.add(setGridGrow(getView(196, 112, 106, 112)), 0, 0, 1, 4);
pane.add(setGridGrow(getView(131, 104, 57, 104)), 1, 0, 1, 3);
pane.add(setGridGrow(getView(93, 26, 42, 26)), 1, 3);
pane.add(setGridGrow(getView(185, 72, 74, 72)), 2, 0, 1, 2);
pane.add(setGridGrow(getView(140, 76, 55, 76)), 2, 2, 1, 2);
return pane;
}
private static Region getView(double prefWidth, double prefHeight, double minWidth, double minHeight) {
Label sizeLabel = new Label();
StackPane view = new StackPane(sizeLabel);
sizeLabel.textProperty().bind(Bindings.createStringBinding(
() -> getDimensionString(view),
view.widthProperty(),
view.heightProperty()
));
setMetrics(view, prefWidth, prefHeight, minWidth, minHeight);
view.setStyle("-fx-background-color: #ddd");
return view;
}
private static String getDimensionString(Region view) {
return String.format("%.1f x %.1f", view.getWidth(), view.getHeight());
}
private static void setMetrics(Region view, double prefWidth, double prefHeight, double minWidth, double minHeight) {
view.setPrefSize(prefWidth, prefHeight);
view.setMinSize(minWidth, minHeight);
}
public static void main(String[] args) {
launch(args);
}
public static Node setGridGrow(Node node) {
Objects.requireNonNull(node);
GridPane.setHgrow(node, Priority.ALWAYS);
GridPane.setVgrow(node, Priority.ALWAYS);
return node;
}
public static RowConstraints getPercentRowConstraints(double percent) {
RowConstraints result = new RowConstraints();
result.setPercentHeight(percent);
return result;
}
public static void setRowPercents(GridPane pane, double... percents) {
pane.getRowConstraints().clear();
for (double percent : percents) {
pane.getRowConstraints().add(getPercentRowConstraints(percent));
}
}
public static ColumnConstraints getPercentColumnConstraints(double percent) {
ColumnConstraints result = new ColumnConstraints();
result.setPercentWidth(percent);
return result;
}
public static void setColumnPercents(GridPane pane, double... percents) {
pane.getColumnConstraints().clear();
for (double percent : percents) {
pane.getColumnConstraints().add(getPercentColumnConstraints(percent));
}
}
}
Update
As a workaround, I wrapped the second column and the third column into separate gridpanes and got what I expected, roughly.
GridPane pane = new GridPane();
setColumnPercents(pane, 40, 27, 33);
pane.setHgap(10);
pane.heightProperty().addListener(observable -> System.out.println(getDimensionString(pane)));
pane.widthProperty().addListener(observable -> System.out.println(getDimensionString(pane)));
pane.add(setGridGrow(getView(196, 112, 106, 112)), 0, 0);
GridPane secondColumn = new GridPane();
secondColumn.setVgap(10);
setRowPercents(secondColumn, 25, 25, 25, 25);
secondColumn.add(setGridGrow(getView(131, 104, 57, 104)), 0, 0, 1, 3);
secondColumn.add(setGridGrow(getView(93, 26, 42, 26)), 0, 3);
pane.add(setGridGrow(secondColumn), 1, 0);
GridPane thirdColumn = new GridPane();
setRowPercents(thirdColumn, 25, 25, 25, 25);
thirdColumn.setVgap(10);
thirdColumn.add(setGridGrow(getView(185, 72, 74, 72)), 0, 0, 1, 2);
thirdColumn.add(setGridGrow(getView(140, 76, 55, 76)), 0, 2, 1, 2);
pane.add(setGridGrow(thirdColumn), 2, 0);
However, this problem is not considered solved with a clean method and a clear mechanism.

Related

how to set scss dynamic class name of margin values

How to set the scss dynamic class name using margin values.
This is what I tried
$spaceamounts: (1, 3, 5, 8, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 110, 120, 130, 140,150,160,170,180,);
$sides: (top, bottom, left, right);
#each $space in $spaceamounts {
#each $side in $sides {
.m#{str-slice($side, 0, 1)}-#{$space} {
margin-#{$side}: #{$space}px !important;
}
.p#{str-slice($side, 0, 1)}-#{$space} {
padding-#{$side}: #{$space}px !important;
}
}
}
So I can use margin/padding class name like pt-1, mt-10
But I want to set the $spaceamounts value as 1~999.
Anyone know how to fix the code?
If you want to create a class for every values between 1 and 999, you can get rid of $spaceamounts and use a #for loop:
$sides: (top, bottom, left, right);
#for $i from 1 through 999 {
#each $side in $sides {
.m#{str-slice($side, 0, 1)}-#{$i} {
margin-#{$side}: #{$i}px !important;
}
.p#{str-slice($side, 0, 1)}-#{$i} {
padding-#{$side}: #{$i}px !important;
}
}
}
For what it's worth, I think that it's not something you should do as it will generate a massive amount of code.

JavaFX TriangleMesh causes heavy overhead/slowness compared to normal Boxes

My goal is to create Boxes with individual images on each side, which I have been completing by using a TriangleMesh to create the boxes, and using a single texture to map the points over the Mesh.
The issue is that I have been experiencing heavy overhead (high ram, long load times and slowness when moving objects in the world) from creating these TriangleMesh, and I'm not sure why fully, but here are a few of my guesses.
I initially tried to use a total of 8 points and reuse the points when creating the individual faces, and wrap the textures, but for some reason the texcoords did not like using only 8 points. As I look at Box's class I see they use 24 points as well as I do, so it seems we cannot reuse points.
2.a I am loading the 3 images into an hbox and then taking a snapshot to then map the coordinates. I am wondering if somehow snapshot is causing issues, or if there is some issue with the amount of pixels.
2.b This further comes into question when I tried turning multiple boxes
that were stacked together into one large box and it still having a
ton of slowness, if not more. I would take a snapshot of x number
of images and then map them onto this one big Box. i.e., if I had
5x5x5 it would be one box with 5 images mapped on each side. Even
with 1 single mesh it still causes slowness. It speeds up if I edit
the "fitWidth/fitHeight" of the imageView which causes a quality
change. To me, it seems like the pixel amounts are the cause. The thing is, if I'm taking the same images and just multiplying them, why is it causing slowness? Especially since when doing a normal box, the single image I was using had more pixels than the other images, so I would think it would be faster by doing the trianglemesh myself.
I don't really have a working example since this was added to an already working program that has data, but I will try to create something if need be.
I'm just trying to figure out why making a TriangleMesh on my own, which has similar code to the Box's code except.
without the face smoothing group, but not sure that matters.
My face array is different, and a bit confused why they have 24 points but the face array only goes from 1-8
int[] faces = {
2, 2, 1, 1, 0, 0, //front
2, 2, 3, 3, 1, 1,
6, 6, 5, 5, 4, 4, //right
6, 6, 7, 7, 5, 5,
10, 10, 9, 9, 8, 8, //back
10, 10, 11, 11, 9, 9,
14, 14, 13, 13, 12, 12,//left
14 ,14, 15, 15, 13, 13,
18, 18, 17, 17, 16, 16,//top
18, 18, 19, 19, 17, 17,
22, 22, 21, 21, 20, 20, //bottom
22, 22, 23, 23, 21, 21`
My texCoords are 6 sets of pairs instead of the 1 set here.
static TriangleMesh createMesh(float w, float h, float d) {
// NOTE: still create mesh for degenerated box
float hw = w / 2f;
float hh = h / 2f;
float hd = d / 2f;
float points[] = {
-hw, -hh, -hd,
hw, -hh, -hd,
hw, hh, -hd,
-hw, hh, -hd,
-hw, -hh, hd,
hw, -hh, hd,
hw, hh, hd,
-hw, hh, hd};
float texCoords[] = {0, 0, 1, 0, 1, 1, 0, 1};
// Specifies hard edges.
int faceSmoothingGroups[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
int faces[] = {
0, 0, 2, 2, 1, 1,
2, 2, 0, 0, 3, 3,
1, 0, 6, 2, 5, 1,
6, 2, 1, 0, 2, 3,
5, 0, 7, 2, 4, 1,
7, 2, 5, 0, 6, 3,
4, 0, 3, 2, 0, 1,
3, 2, 4, 0, 7, 3,
3, 0, 6, 2, 2, 1,
6, 2, 3, 0, 7, 3,
4, 0, 1, 2, 5, 1,
1, 2, 4, 0, 0, 3,
};
TriangleMesh mesh = new TriangleMesh(true);
mesh.getPoints().setAll(points);
mesh.getTexCoords().setAll(texCoords);
mesh.getFaces().setAll(faces);
mesh.getFaceSmoothingGroups().setAll(faceSmoothingGroups);
return mesh;
}
I also had heard that there were improvements to 3D with Version 9. I have been trying to update the past few days to 11 with issues (I had tried 10 before but a lot of my code needed fixings), and 9 isn't downloading so I wanted to ask before trying to put in more effort to get 11 working if it will in fact improve the situation, but I am still wondering why trianglmesh is so slowed comparatively. I'm maybe making 1000 boxes max.
Thank you
EDIT:
Example of how I create the images.
public BoxMesh(width, height,depth, int stack)
{
float width = width;
float height = height;
float depth = depth
List<ImageView> imageList = new ArrayList();
imageList.add(new ImageView(new Image("file:"C:\\file1.jpg"));
HBox h = new HBox();
Image image = null;
for(int i = 0; i < stack; i++)
{
image = new Image("file:"C:\\file2.jpg");
ImageView iv = new ImageView(image);
iv.setFitWidth(image.getWidth()/2); //decreases quality to
iv.setFitHeight(image.getHeight()/2); //speed up program
h.getChildren().add(iv);
}
imageList.add(new ImageView(h.snapshot(null,null)));
VBox v = new VBox();
Image image = null;
for(int i = 0; i < stack; i++)
{
image = new Image("file:"C:\\file3.jpg");
ImageView iv = new ImageView(image);
iv.setFitWidth(image.getWidth()/2);
iv.setFitHeight(image.getHeight()/2);
v.getChildren().add(iv);
}
imageList.add(new ImageView(v.snapshot(null, null)));
PhongMaterial p = new PhongMaterial();
HBox hb = new HBox();
hb.getChildren().addAll(imageList);
WritableImage snapshot = hb.snapshot(null, null);
if(snapshot.isError())
{
System.out.println(snapshot.exceptionProperty().getValue());
}
p.setDiffuseMap(snapshot);

Android Things Raspberry Pi UART Reliability Issue

I am receiving data via UART from an Arduino. I followed the documentation and I get the data as expected most of the time. Sometimes the read does not finish, gets a few zeroes then starts a new read with the rest of the data. This can be seen in the example output, all the data is there but split into 2 reads. I am only sending data once a second so there should be plenty time.
My Code:
private UartDeviceCallback mUartCallback = new UartDeviceCallback() {
#Override
public boolean onUartDeviceDataAvailable(UartDevice uart) {
// Read available data from the UART device
try {
readUartBuffer(uart);
} catch (IOException e) {
Log.w(TAG, "Unable to access UART device", e);
}
// Continue listening for more interrupts
return true;
}
private void readUartBuffer(UartDevice uart) throws IOException {
// Maximum amount of data to read at one time
final int maxCount = 20;
byte[] buffer = new byte[maxCount];
uart.read(buffer, maxCount);
Log.i(TAG, Arrays.toString(buffer));
}
#Override
public void onUartDeviceError(UartDevice uart, int error) {
Log.w(TAG, uart + ": Error event " + error);
}
};
Example output:
[50, 48, 54, 46, 52, 53, 32, 50, 49, 46, 55, 48, 32, 51, 51, 46, 51, 48, 32, 0]
[50, 48, 54, 46, 57, 51, 32, 50, 49, 46, 55, 48, 32, 51, 51, 46, 51, 48, 32, 0]
[50, 48, 54, 46, 48, 52, 32, 50, 49, 46, 55, 48, 32, 51, 51, 46, 51, 48, 32, 0]
[50, 48, 55, 46, 51, 52, 32, 50, 49, 46, 55, 48, 32, 51, 51, 46, 51, 48, 32, 0]
[50, 48, 54, 46, 53, 48, 32, 50, 49, 46, 55, 48, 32, 51, 51, 46, 51, 48, 32, 0]
[50, 48, 55, 46, 51, 54, 32, 50, 49, 46, 55, 48, 32, 51, 51, 46, 51, 48, 32, 0]
[50, 48, 54, 46, 57, 51, 32, 50, 49, 46, 55, 48, 32, 51, 51, 46, 0, 0, 0, 0]
[51, 48, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[50, 48, 55, 46, 51, 56, 32, 50, 49, 46, 55, 48, 32, 51, 51, 46, 0, 0, 0, 0]
[51, 48, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[50, 48, 54, 46, 52, 57, 32, 50, 49, 46, 55, 48, 32, 51, 51, 46, 51, 48, 32, 0]
I am quite sure the problem is the R Pi since I am looping back from the Arduino to my PC with no problems. I also found that unless I make maxCount the exact number of bytes I am sending, the problem is more prevalent. Whereby, the data comes in random packages but in the correct order. Am I wasting my time? Should I just use I2C?
"Should I just use I2C?" - no.
There is no problem with R Pi because "all the data is there". They (can be) split (or not, especially if it short) into 2 (or more) reads, because onUartDeviceDataAvailable() can be fired before ALL data available (but only part of it was available), so you should read them in a loop until you receive all of them. And, from your code: maxCount - Maximum amount of data to read at one time is not size for ALL data, it's max. size for one-time read. You code can be something like that (NB! it's just example, not complete solution):
private void readUartBuffer(UartDevice uart) throws IOException {
// Buffer for all data
final int maxSizeOfAllData = 30;
byte[] completaDataBuffer = new byte[maxSizeOfAllData];
// Buffer for one uart.read() call
final int maxCount = 20;
byte[] buffer = new byte[maxCount];
int bytesReadOnce; // number of actually available data
int totalBytesRead = 0;
// read all available data
while ((bytesReadOnce = uart.read(buffer, maxCount))) > 0) {
// add new data to "all data" buffer
for (int i = 0; i < bytesReadOnce; i++) {
completaDataBuffer[totalBytesRead + i] = buffer[i]
if (totalBytesRead + i == maxSizeOfAllData - 1) {
// process complete buffer here
...
totalBytesRead = 0;
break;
}
}
totalBytesRead += bytesReadOnce;
}
}
Also, take a look at NmeaGpsModule.java from Android Things user-space drivers and LoopbackActivity.java from Android Things samples.
I ended up adding an end character (0x36) and using a dataCompleteFlag:
private void readUartBuffer(UartDevice uart) throws IOException {
// Maximum amount of data to read at one time
final int maxCount = 32;
byte[] buffer = new byte[maxCount];
boolean dataCompleteFlag = false;
uart.read(buffer, maxCount);
Log.i(TAG, Arrays.toString(buffer));
if (!dataCompleteFlag) {
for (int i = 0; i < maxCount; i++) {
if (buffer[i] == 36) {
dataCompleteFlag = true;
dataCount = 0;
}
else if(dataCount > maxCount) {
dataCount = 0;
}
else if(buffer[i] != 0) {
finalDataBuffer[dataCount] = buffer[i];
dataCount++;
}
}
}
if (dataCompleteFlag) {
//process data
}
}
#Override
public void onUartDeviceError(UartDevice uart, int error) {
Log.w(TAG, uart + ": Error event " + error);
}
};

Converting to functional Java style

How would one re-write the following in proper Java 8 functional style using filter, collector, etc:
private BigInteger calculateProduct(char[] letters) {
int OFFSET = 65;
BigInteger[] bigPrimes = Arrays.stream(
new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31,
37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89,
97, 101, 103, 107, 109, 113 })
.mapToObj(BigInteger::valueOf)
.toArray(BigInteger[]::new);
BigInteger result = BigInteger.ONE;
for (char c : letters) {
//System.out.println(c+"="+(int)c);
if (c < OFFSET) {
return new BigInteger("-1");
}
int pos = c - OFFSET;
result = result.multiply(bigPrimes[pos]);
}
return result;
}
#Test public void test() {
assertThat(calculateProduct(capitalize("carthorse"))).isEqualTo(calculateProduct(capitalize("orchestra")));
}
private char[] capitalize(String word) {
return word.toUpperCase().toCharArray();
}
You may do it like this:
static final BigInteger[] PRIMES
= IntStream.of(
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53,
59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113)
.mapToObj(BigInteger::valueOf)
.toArray(BigInteger[]::new);
private BigInteger calculateProduct(char[] letters) {
final int OFFSET = 65;
final CharBuffer cb = CharBuffer.wrap(letters);
if(cb.chars().anyMatch(c -> c<OFFSET))
return BigInteger.ONE.negate();
return cb.chars()
.mapToObj(c -> PRIMES[c-OFFSET])
.reduce(BigInteger.ONE, BigInteger::multiply);
}
Note that moving the creation of the PRIMES array out of the method, to avoid generating it again for each invocation, is an improvement that works independently of whether you use loops or “functional style” operations.
Also, your code doesn’t handle characters being too large, so you might improve the method to
private BigInteger calculateProduct(char[] letters) {
final int OFFSET = 65;
final CharBuffer cb = CharBuffer.wrap(letters);
if(cb.chars().mapToObj(c -> c-OFFSET).anyMatch(c -> c<0||c>PRIMES.length))
return BigInteger.ONE.negate();
return cb.chars()
.mapToObj(c -> PRIMES[c-OFFSET])
.reduce(BigInteger.ONE, BigInteger::multiply);
}
I can't tell why you want that, but may be this (which creates many more objects and is more verbose):
private static BigInteger calculateProduct(char[] letters) {
int OFFSET = 65;
BigInteger[] bigPrimes = Arrays.stream(
new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31,
37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89,
97, 101, 103, 107, 109, 113 })
.mapToObj(BigInteger::valueOf)
.toArray(BigInteger[]::new);
Optional<Character> one = IntStream.range(0, letters.length)
.mapToObj(x -> letters[x])
.filter(x -> x < OFFSET)
.findAny();
if (one.isPresent()) {
return new BigInteger("-1");
} else {
return IntStream.range(0, letters.length)
.mapToObj(x -> letters[x])
.parallel()
.reduce(
BigInteger.ONE,
(x, y) -> {
int pos = y - OFFSET;
return x.multiply(bigPrimes[pos]);
},
BigInteger::multiply);
}
}

I could not figure out how to dereference this pointer for a sizeof() and void pointers

I could not figure out how to dereference this pointer...
sizeof(shapetest2->tripsName) in this line below, it is obviously not going to work because it is a pointer, i could not figure out how to dereference it? (is it easy? or is it a couple steps?, i've tried several things, but could not get close) I am not an experience enough coder to figure this particular circumstance out.
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(shapetest2->tripsName), shapetest2->tripsName);
here is the setup code. (i am experimenting with a VOB in openGL ES 1.5, so if it looks odd, that is why) if i forgot some important setup or definitions, or code, let me know and i'll include it.
GLsizeiptr dataSize;
GLsizeiptr indexSize;
typedef struct shapeBase {
void *stripsName[maxStrips];
void *tripsName;
void *fansName;
int totStrips;
int stripsNum[maxStrips];
int tripsNum;
int totFans;
int fansBgn[maxStrips];
int fansNum[maxStrips];
void *dataName;
void *listOfInserts;
Vertex3D center;
Vertex3D radius;
int damageMax;
float weight;
GLuint bufferName;
GLuint indexName;
} shapeBase;
static const GLushort test2Trips[] =
{
0, 1, 3, 1, 2, 3,
4, 5, 7, 5, 6, 7,
8, 9, 11, 9, 10, 11,
12, 13, 15, 13, 14, 15,
16, 17, 19, 17, 18, 19,
20, 21, 23, 21, 22, 23,
24, 25, 27, 25, 26, 27,
28, 29, 31, 29, 30, 31,
32, 33, 35, 33, 34, 35,
36, 37, 39, 37, 38, 39,
40, 41, 43, 41, 42, 43,
44, 45, 47, 45, 46, 47,
};
//-------------------------
static inline void shapetest2Setup(void)
{
shapetest2 = malloc(sizeof(shapeBase));
shapetest2->stripsName[1] = NULL;
shapetest2->tripsName = &test2Trips;
shapetest2->fansName = NULL;
shapetest2->dataName = &test2Data;
shapetest2->totStrips = 0;
shapetest2->stripsNum[1] = 0;
shapetest2->tripsNum = 72;
shapetest2->totFans = 0;
shapetest2->listOfInserts = NULL;
shapetest2->center = Vertex3DMake( 0.000000, -0.000000, 2.000000 );
shapetest2->radius = Vertex3DMake( 1.000000, 1.000000, 2.000000 );
dataSize = sizeof(test1Data) + sizeof(test2Data);
glGenBuffers(1, &mainBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mainBuffer);
glBufferData(GL_ARRAY_BUFFER, dataSize, NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(test1Data), test1Data);
glBufferSubData(GL_ARRAY_BUFFER, sizeof(test1Data), sizeof(test2Data), test2Data);
// glGenBuffers(1, &shapetest2->indexName);
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, shapetest2->indexName);
// glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(test2Trips), test2Trips, GL_STATIC_DRAW);
indexSize = sizeof(test1Trips) + sizeof(test2Trips);
glGenBuffers(1, &mainIndex);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mainIndex);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexSize, NULL, GL_STATIC_DRAW);
}
//------------------------------------------------------
static inline void DrawOutShape(void)
{
glBindBuffer(GL_ARRAY_BUFFER, mainBuffer);
glVertexPointer(3, GL_FLOAT, sizeof(VertexData3D), (void*)0);
glNormalPointer(GL_FLOAT, sizeof(VertexData3D), (void*)12);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mainIndex);
// glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(theInsert->insertName->tripsName), theInsert->insertName->tripsName);
// glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(test1Trips), test1Trips);
// glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, sizeof(test1Trips), sizeof(test2Trips), shapetest2->tripsName);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(shapetest2->tripsName), shapetest2->tripsName);
glDrawElements(GL_TRIANGLES, theInsert->insertName->tripsNum, GL_UNSIGNED_SHORT, (void*)0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
polys += theInsert->insertName->tripsNum;
}
(theInsert is a handle (pointer to pointer) of the shapetest2, so you can substitute shapetest2 if you see "theInsert->insertName")
if i comment out the offending line, and uncomment the line above, it is working, but i need this indirection, (and actually i need another level of indirection that you can see in another commented out line) but if i can figure out how to dereference this line, i should be able to do it for another level of indirection?)
sizeof is compile-time constant that works on exact type you provide. sizeof of void* is just a size of pointer on your machine (likely 4/8 bytes). Just store size along with other data.

Resources