473,748 Members | 8,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

casting problem (int * to int*)

hi,

i got this opengl/c++ code:

<code>
void render(CMesh *mesh){
...
float *pVertices;
int *pIndices;

//WORKS FINE
pVertices = (GLfloat *)mesh->getVertices( ); // (A)
//PROBLEMS HERE!!!!
pIndices = (int *)mesh->getFaceIndices (); // (B)

...
}

class:

int *CMesh::getFace Indices() const{
return faceIndices;
}

float *CMesh::getVert ices() const{
return vertices;
}

Class CMesh
{
...
float *vertices = new float[numVertices * 3];;
int *faceIndices = new int[numFaces * 3];
...
}
</code>

the two arrays get filled at runtime.
for the the opengl rendering part, i need to have a pointer to a
float-array containing the vertices and a pointer to an int-array
conatining the indices of the triangles.

to get them from my mesh-object i cast them in the render-function.
the floatconversion (A) works. "pVertices" points to the same data as
the member variable "vertices" of the mesh-object. but when i try to
cast the pointer of my integerarray (B), a dataloss occurs. when i
loop through pIndices i get lesser data. only every 3rd integer of the
original array. the last 3 values are correct.
this must be a casting problem. why does it work with floats, but not
with int?
i tried (GLint *) and (int *) casting (they seem to be the same size
anyway, according to sizeof())... no success. any ideas?

TIA
ghostdog
Jul 19 '05 #1
2 2492
"ghostdog" <su***@gmx.at > wrote in message
news:e6******** *************** ***@posting.goo gle.com...
....
| //WORKS FINE
| pVertices = (GLfloat *)mesh->getVertices( ); // (A)
| //PROBLEMS HERE!!!!
| pIndices = (int *)mesh->getFaceIndices (); // (B)
....
| float *vertices = new float[numVertices * 3];;
| int *faceIndices = new int[numFaces * 3];
....
| the two arrays get filled at runtime.
| for the the opengl rendering part, i need to have a pointer to a
| float-array containing the vertices and a pointer to an int-array
| conatining the indices of the triangles.
....
| to get them from my mesh-object i cast them in the render-function.
| the floatconversion (A) works. "pVertices" points to the same data as
| the member variable "vertices" of the mesh-object. but when i try to
| cast the pointer of my integerarray (B), a dataloss occurs. when i
| loop through pIndices i get lesser data. only every 3rd integer of the
| original array. the last 3 values are correct.
| this must be a casting problem. why does it work with floats, but not
| with int?
| i tried (GLint *) and (int *) casting (they seem to be the same size
| anyway, according to sizeof())... no success. any ideas?

I do not think that this is a casting problem. In any case, the code
that you have posted does not contain a problem by itself.

However, there are many caveats when dealing with this kind of
indexed vertex buffers: for example an index value will
(typically) have to be multiplied by 3 to get the first coordinate
of a vertex within your float array.
... but this is getting OT here.

My suggestion would be to post a more complete code example,
and to post it on a technology-specific forum (e.g. in comp.graphics.* ?,
or on a forum supported by an OpenGL vendor... ).
Regards,
--
http://ivan.vecerina.com
Jul 19 '05 #2
On 15 Sep 2003 07:30:11 -0700 in comp.lang.c++ :

If your functions return "float*"and "int*" respectively,
and you assigning those values to "float*" and "int*"
types,

I'm curious; Why cast ?
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2284
by: Vinodh Kumar | last post by:
I see that casting changes the value of a pointer in case of multiple inheritance.In single inheritance also it is the same know?Isn't it? Vinodh Kumar P
4
3478
by: Jacob Jensen | last post by:
This question has probably been asked a million time, but here it comes again. I want to learn the difference between the three type cast operators: static_cast, reinterpret_cast, dynamic_cast. A good way to do this is by example. So I will give an example and please tell me what you think: I have a base class A with a virtual destructor, and a class B that is it inherits publicly from A and defines som extra stuff.
231
23198
by: Brian Blais | last post by:
Hello, I saw on a couple of recent posts people saying that casting the return value of malloc is bad, like: d=(double *) malloc(50*sizeof(double)); why is this bad? I had always thought (perhaps mistakenly) that the purpose of a void pointer was to cast into a legitimate date type. Is this wrong? Why, and what is considered to be correct form?
14
2631
by: mr_semantics | last post by:
I have been reading about the practise of casting values to unsigned char while using the <ctype.h> functions. For example, c = toupper ((unsigned char) c); Now I understand that the standard says this about the <ctype.h> functions: "The header <ctype.h> declares several functions useful for classifying and mapping characters.166) In all cases the argument is an int, the
3
1681
by: Kurt | last post by:
i just can't figure out why something im doing is not working correctly.... public interface IInterface { int someProperty { get; set; }
7
3677
by: yufufi | last post by:
lets say we have a 'shape' class which doesn't implement IComparable interface.. compiler doesn't give you error for the lines below.. shape b= new shape(); IComparable h; h=(IComparable)b; but it complains for the following lines
44
2235
by: Agoston Bejo | last post by:
What happens exactly when I do the following: struct A { int i; string j; A() {} }; void f(A& a) { cout << a.i << endl;
17
2227
by: sophia.agnes | last post by:
Hi , I was going through peter van der linden's book Expert C programming, in this book there is a section named "How and why to cast" the author then says as follows (float) 3 - it's a type conversion and the actual bits change. if you say (float) 3.0 it is a type disambiguation,and the compiler can plant the correct bits in the first place.some people say that
32
2386
by: alex.j.k2 | last post by:
Hello all, I have "PRECISION" defined in the preprocessor code and it could be int, float or double, but I do not know in the code what it is. Now if I want to assign zero to a "PRECISION" variable, which of the following lines are correct:
101
4331
by: Tinkertim | last post by:
Hi, I have often wondered if casting the return value of malloc() (or friends) actually helps anything, recent threads here suggest that it does not .. so I hope to find out. For instance : char *tmp = NULL;
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9541
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8242
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4602
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.